#i have /[locale]/path/to/page but i also want i have /path/to/page to be available

1 messages · Page 1 of 1 (latest)

somber forge
#

/en/path/to/page, /es/path/to/page, /fr/path/to/page is great but i also want /path/to/page available

brittle nestBOT
#

Hi @somber forge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To achieve what you're looking for, you can use Astro's i18n routing configuration with the prefixDefaultLocale option set to false. This will allow you to have both localized paths (/[locale]/path/to/page) and a default path (/path/to/page) available.

Here's how you can configure this in your astro.config.mjs:

import { defineConfig } from "astro/config";

export default defineConfig({
  i18n: {
    defaultLocale: "en",
    locales: ["en", "es", "fr"],
    routing: {
      prefixDefaultLocale: false
    }
  }
});

With this configuration:

  1. /en/path/to/page, /es/path/to/page, and /fr/path/to/page will be available for their respective locales.
  2. /path/to/page will be available and will serve the content for the default locale (in this case, English).

However, there are a few important points to note:

  1. Your default language content (English in this case) should be placed directly in the src/pages/ directory, not in a localized folder.
  2. Other languages should have their content in their respective locale folders (e.g., src/pages/es/, src/pages/fr/).

Here's an example of how your file structure might look:

src/
  pages/
    path/
      to/
        page.astro  (English version)
    es/
      path/
        to/
          page.astro  (Spanish version)
    fr/
      path/
        to/
          page.astro  (French version)

This setup allows you to have both /path/to/page (which serves the English content) and /[locale]/path/to/page for other languages.

For more details on this configuration, you can refer to the Astro documentation on i18n routing (https://docs.astro.build/en/guides/internationalization/#routing).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: