-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Astro i18n doesn't return the 404 page for incorrect URL locale codes #15098
Description
Astro Info
Astro v5.16.6
Node v22.18.0
System Windows (x64)
Package Manager unknown
Output server
Adapter @astrojs/node
Integrations @astrojs/react
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When creating an Astro SSR multilanguage website with the following config:
export default defineConfig({
adapter: node({
mode: 'standalone',
}),
output: 'server',
i18n: {
locales: ["en", "de"],
defaultLocale: "en",
routing: {
prefixDefaultLocale: true,
},
},
});
And directory structure:
- src
- pages
- [locale]
- index.astro
- 404.astro
- [locale]
- pages
Then making requests to: http://localhost:4321/en/ or http://localhost:4321/de/ results into an HTTP response with code 200, returning /pages/[locale]/index.astro in the response body as expected.
However, if the user tries to make an HTTP request with an invalid language code (not specified in config), for example: http://localhost:4321/asdf/, it results into an HTTP response with code 404, returning /pages/[locale]/index.astro in the response body, instead of /pages/404.astro
Example in this repository:
https://github.com/jonas-s-s-s/astro-not-404
https://stackblitz.com/github/jonas-s-s-s/astro-not-404
What's the expected result?
Making an HTTP request containing an invalid locale code in the URL (for example http://localhost:4321/asdf/ instead of http://localhost:4321/en/) should always result into an HTTP response with code 404, containing the 404.astro page in its body - current implementation does NOT return the 404 page in the response body.
Link to Minimal Reproducible Example
https://stackblitz.com/github/jonas-s-s-s/astro-not-404
Participation
- I am willing to submit a pull request for this issue.