Next.js Discord

Discord Forum

How to set up this rewrite to work in a certain way?

Answered
dperolio posted this in #help-forum
Open in Discord
Hello, I'm trying to set up internationalization. I've added all of my page routes inside of app/[lang]. The thing is, I want the default to be en and when it is en (e.g. /en/products), I want to rewrite the URL to not include /en, so it would just be /products. Essentially, I don't ever want to see /en.

This rewrite accomplishes that, but it also makes all other langs not work, e.g. /nl/products:

async rewrites () {
    return [
      {
        source: '/:path*',
        destination: '/en/:path*'
      }
    ];
  }


Do you know how I can fix the behavior?
Answered by Sun bear
You asked for what Chat Gpt would say, here's what it said, may wanna try it.
View full answer

5 Replies

I think it will involve using
has: [
  {
    type: 'header',
    key: 'accept-language',
    value: 
  }
]

And then I set the value of accept-language in the middleware. I'm not sure how to set up the value regex in the rewrite though.
I guess that won't work, since you can't modify the header, and the header doesn't necessarily match the lang path.
Open to other ideas. Maybe just set up the rewrite in my hosting provider (Netlify) instead?
Sun bear
You asked for what Chat Gpt would say, here's what it said, may wanna try it.
Answer
ChatGPT too smart. Thanks, I didn't consider that. That solved it.