-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Custom 404 pages in localized sites #12175
Copy link
Copy link
Labels
- P3: minor bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)feat: i18nRelated to internalization (scope)Related to internalization (scope)feat: routingRelated to Astro routing (scope)Related to Astro routing (scope)pkg: astroRelated to the core `astro` package (scope)Related to the core `astro` package (scope)triage: failedTriage failed unexpectedly and can be retriedTriage failed unexpectedly and can be retriedtriage: fix pendingReporter needs to verify the triage bot fix worksReporter needs to verify the triage bot fix works
Description
Metadata
Metadata
Assignees
Labels
- P3: minor bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)feat: i18nRelated to internalization (scope)Related to internalization (scope)feat: routingRelated to Astro routing (scope)Related to Astro routing (scope)pkg: astroRelated to the core `astro` package (scope)Related to the core `astro` package (scope)triage: failedTriage failed unexpectedly and can be retriedTriage failed unexpectedly and can be retriedtriage: fix pendingReporter needs to verify the triage bot fix worksReporter needs to verify the triage bot fix works
Type
Fields
No fields configured for Bug.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I'm using Astro's i18n options to create a localized site in 4 languages: en, ja, zh, ko. A hard requirement for my use case is that we use the
prefixDefaultLocale: truesetting to ensure that the default locale (en) always appears in the path just like the others.One thing I need is the ability to create a custom 404 page that gives users instructions on what to do next when they reach a page that doesn't exist. Before I updated to the multi-folder structure, this was achievable by placing a
404.astroin thepagesdirectory. However, this page was not localized properly due to there not being any locale detection present. Since moving to the new folder-based hierarchy, I noticed that the404.astrodoesn't appear in thedistfolder after runningastro build.Adding a custom
404.astrotopages/[lang]works if you visit the slug directly (e.g./en/404), but it doesn't work when actually hitting a 404. I've managed to override this in Vercel by putting in a Vercel redirect that takes any 404 to the/en/404route then using some client side scripting to push the user to the correct page.What's the expected result?
I would like to be able to create a custom
404.astroinpagesthat routes to the custom404.astroinpages/[lang]so that localized 404 pages may be served. Ideally, it would be good to control this viaastro.config.mjs. Having the ability to simply set up locale-based routing to the major pages likeindex.astroand404.astrowould save a lot of time.Link to Minimal Reproducible Example
https://stackblitz.com/edit/astro-no-localized-404
Participation