Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Rewrites are in conflict with i18n #68706

Closed
yunsii opened this issue Aug 9, 2024 · 3 comments
Closed

Rewrites are in conflict with i18n #68706

yunsii opened this issue Aug 9, 2024 · 3 comments
Labels
bug Issue was opened via the bug report template. Internationalization (i18n) Related to Internationalization with Next.js. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router.

Comments

@yunsii
Copy link
Contributor

yunsii commented Aug 9, 2024

Link to the code that reproduces this issue

https://github.com/yunsii/reproduciton-nextjs-rewrites-i18n

To Reproduce

{
  source: "/:path((?!api/).*)",
  has: [
    {
      type: "host",
      value: "localhost",
    },
  ],
  destination: `/test.com/:path*`,
}

Without i18n config, the rewrites config works very well. But with i18n config, the homepage localhost:3000 goes to 404, I have to add extra rewrite rule:

{
  source: "/",
  has: [
    {
      type: "host",
      value: "localhost",
    },
  ],
  destination: `/test.com`,
}

to make the homepage work as expected.

Current vs. Expected behavior

I18n config should not affect rewrites config, isn't it?

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Thu Oct 5 21:02:42 UTC 2023
  Available memory (MB): 40115
  Available CPU cores: 16
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.22.15
  pnpm: 6.11.0
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), Navigation, Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

@yunsii yunsii added the bug Issue was opened via the bug report template. label Aug 9, 2024
@github-actions github-actions bot added Internationalization (i18n) Related to Internationalization with Next.js. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router. labels Aug 9, 2024
@samcx
Copy link
Member

samcx commented Aug 12, 2024

@yunsii Thank you for submitting an issue!

Curious, does it work with beforeFiles instead?

@yunsii
Copy link
Contributor Author

yunsii commented Aug 13, 2024

Curious, does it work with beforeFiles instead?

All requests return 404 if I change afterFiles to beforeFiles directly 😦

@samcx
Copy link
Member

samcx commented Aug 13, 2024

@yunsii Have you taken a look at this in our documentation → https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites#rewrites-with-i18n-support?

@vercel vercel locked and limited conversation to collaborators Aug 13, 2024
@samcx samcx converted this issue into discussion #68855 Aug 13, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Issue was opened via the bug report template. Internationalization (i18n) Related to Internationalization with Next.js. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

2 participants