Domain routing and i18n configuration cause incorrect URL redirection.
The issue involves incorrect URL redirection in Next.js when using domain routing with i18n, where the Location header uses the wrong hostname. The fix requires understanding domain routing and i18n configuration, but the exact implementation scope is somewhat unclear due to the complexity of domain routing rules.
https://github.com/SLMNBJ/nextjs-domain-routing-redirect
npm run devCurrent:
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
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
Internationalization (i18n), Middleware, Navigation
next dev (local), next start (local)
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.
<img width="959" alt="Screenshot 2024-08-01 at 10 46 48" src="https://github.com/user-attachments/assets/18592329-c386-4
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!