Incorrect Location header URL with domain routing i18n
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/SLMNBJ/nextjs-domain-routing-redirect
To Reproduce
npm run dev- go to http://localhost:3000/en
- Click the blog link
Current vs. Expected behavior
Current:
Next.js redirects to the wrong hostname. Location header URL uses the matched defaultLocale domain from i18n.domains to prefix the URL
Expected behavior:
Next.js location header should use the current hostname I'm navigating for the location header. If I click http://localhost:3000/fr/will-be-removed/blog I expect to be http://localhost:3000/fr/blog
Provide environment information
Node.js v18.20.3
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.6.0: Fri Jul 5 17:56:41 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 10
Binaries:
Node: 18.20.3
npm: 10.7.0
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 14.2.5 // Latest available version is detected (14.2.5).
eslint-config-next: 14.2.5
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Internationalization (i18n), Middleware, Navigation
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
I have multiple environments with different domains. I use Domain Routing i18n to configure each domain's locale and add redirects to redirect old URLs to new ones.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and run npm run dev, then reproduce the redirect from /en or /fr/will-be-removed/blog. Trace the i18n domain-routing and middleware navigation that generates the Location header; done means the redirect preserves the current hostname while normalizing the locale path to /fr/blog.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, react
- Domain
- frontend, internationalization, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100