I use the redirection by language as the below link.
The nf_lang cookie is as the below.
The content of the _redirection is as the below.
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.
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?
_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:
Choose zh-CN and the nf_lang will be set to zh-CN, then enter the root URL /.
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 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"]}
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.
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.
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.
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.
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?