Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Location header URL with domain routing i18n #68388

Open
SalmenBejaoui opened this issue Aug 1, 2024 · 1 comment · May be fixed by #75115
Open

Incorrect Location header URL with domain routing i18n #68388

SalmenBejaoui opened this issue Aug 1, 2024 · 1 comment · May be fixed by #75115
Labels
bug Issue was opened via the bug report template. Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@SalmenBejaoui
Copy link

SalmenBejaoui commented Aug 1, 2024

Link to the code that reproduces this issue

https://github.com/SLMNBJ/nextjs-domain-routing-redirect

To Reproduce

  1. npm run dev
  2. go to http://localhost:3000/en
  3. 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

Screenshot 2024-08-01 at 10 37 21

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.

Screenshot 2024-08-01 at 10 46 48
@SalmenBejaoui SalmenBejaoui added the bug Issue was opened via the bug report template. label Aug 1, 2024
@github-actions github-actions bot added Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Aug 1, 2024
@SalmenBejaoui SalmenBejaoui changed the title Redirects prefix redirect Location header with defaultLocale matched domain from i18n.domains Incorrect Location header URL with domain routing i18n Aug 1, 2024
@SalmenBejaoui
Copy link
Author

SalmenBejaoui commented Aug 3, 2024

After further investigation, I found this:

Using domain routing configuration, and as my redirect rule doesn't have a has option to match the host, Next.js will duplicate the rule using the domain routing domains putting the new rules before the default one. Redirection rule order is important, and in this case using localhost, Next.js will match the correct rule but with wrong destination.

With Domain Routing
Screenshot 2024-08-03 at 10 04 59

Without Domain Routing
Screenshot 2024-08-03 at 10 05 28

It seems something is happening here still not clear to me

function processRoutes<T>(

@SalmenBejaoui SalmenBejaoui linked a pull request Jan 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant