Home
Support Forums

The behavior of Netlify Dev in local is different to the Netlify platform when using language redirection

Hi all,

I use the redirection by language as the below link.

The nf_lang cookie is as the below.
image

The content of the _redirection is as the below.
image

It works fine on Netlify but not in the local environment that I use netlify dev command.
In my local environment, It cannot redirect by the nf_lang, but if I use NEXT_LOCALE cookie it can work fine.

I have netlify login and netlify link like the below link.

The state.json file exists in the .netlify folder and the siteId is set.
image

My demo site is here.
https://sfnetlify.netlify.app/

My demo code on GitHub is here.

Test Case1:

  1. Choose the δΈ­ζ–‡(繁體)
    image
  2. enter https://sfnetlify.netlify.app/
  3. It will be redirected to Create Next App

Test Case2:

  1. Choose the English
    image
  2. enter https://sfnetlify.netlify.app/
  3. It will be redirected to Create Next App

It works fine on the Netlify platform but not on the local machine when using netlify dev.
How can I make the netlify dev environment is the same as the Netlify platform?

Thank you.

Hi @antai0926

_redirects file goes in the publish directory. I believe NextJS uses public folder to store static files and you should try to copy the file to that folder to see if it works.

Hi @hrishikesh ,
Thanks for your reply.
I try to move the _redirects file into the publish directory.
It’s failed to redirect to the correct lang path both on the Netlify platform and my local environment.
The _redirects file must be in the root of the project folder that works fine on the Netlify platform.

Although I move it to the public directory, after running netlify dev command, It’s also failed to redirect to the correct URL according to the nf_lang cookie in my local environment.

For example:

  1. Choose zh-CN and the nf_lang will be set to zh-CN, then enter the root URL /.
  2. It will enter the preferred language path of the browser not enter the /zh-cn path.

I found that the console shows some error messages like the below picture.

I have installed the netilfy-cli in global(npm install -g netlify-cli).
What else should I do?

Thank you for your patience.

Hi @antai0926

Next/image has issues with SVG (search these forums/the Interwebs for more) this is nothing to do with Netlify CLI.

1 Like

I attached the video to describe this problem.
Hope it can help.

Hi @antai0926,

I changed your _redirects file to netlify.toml file and now the redirects seem to work even locally:

[[redirects]]
  from = "/"
  to = "/en-US"
  status = 302
  conditions = {Language = ["en_US"]}

[[redirects]]
  from = "/"
  to = "/zh_TW"
  status = 302
  conditions = {Language = ["zh_TW"]}

[[redirects]]
  from = "/"
  to = "/zh_CN"
  status = 302
  conditions = {Language = ["zh_CN"]}

Would you give this a try?

Hi @hrishikesh ,
I have tried to replace the _redirects file to netlify.toml file.
It doesn’t work both on the Netlify platform and in my local environment.
So I revert them and test again, It works fine when I use _redirects file.
The test result is like this.
image
Although I place the netlify.toml file into the public directory or the root directory of my project, both of them not work.
The below link is the hisroty of the git commits.

Thank you.

While I find this behaviour strange, I have got it working locally as well as on Netlify by keeping both, the _redirects file and netlify.toml file in the root of the repo.

When I previously said it worked, I didn’t realise I had kept the _redirects file which I thought I deleted.

Hi @hrishikesh,
Although I keep both _redirects file and netlify.toml file, it still doesn’t work in my local environment.
Did you delete the NEXT_LOCALE cookie in your browser?
The NEXT_LOCALE makes the redirection correctly in the local environment, but it should belong to the Next.js development server (Vercel) not the Netlify.
image

Thank you.

Hi @hrishikesh ,
The document in the below link uses the 302 status code.


In this situation, it can’t redirect to the correct language path according to the nf_lang cookie in my local environment.
When I use the 301 status code, it works fine.
image
Why?
However, I think it is still not the same as the result that I deploy to the Netlify platform.
It can redirect to the correct language path on the Netlify platform when I use the 302 status code.
If I use the netlify dev tool, should the result be the same between the local environment and the Netlify platform?

If no.
Is there any documentation that describes the difference of result between on production and local environment, that I can avoid some bugs when I deploy to the production environment on Netlify platform because the behavior is not the same between local environment and the Netlify platform?

Thank you very much.

Hi @antai0926,

Yes, I don’t have any NEXT_LOCALE cookie in my browser and the redirection works fine. I’ll produce a video to reciprocate the video in a while.

Here’s a video in Netlify Dev using only _redirects: