Redirect by browser language

Hi guys,
I’m trying to setup a redirect based on the language of the browser, tried a lot of variations but can’t find the correct syntax.

Here is my actual entry in the _redirects file:

/ 302 Language=it

What I’m expecting is:
If my language is italian,then redirect me to from every url.


Thanks a lot!

Hi Federico and sorry to hear about the trouble! First off, I don’t see that redirect on that site - there are about 40 non-language 301 redirects like this:

"/prodotti/ev-smart-2/" to "/prodotti"

so, either you removed it, or you are not deploying what you think you are.

Next up, with that configuration, you’ll redirect ONLY the main page and ONLY if you DON’T have an index.html so I think that is probably not what you want :slight_smile: If you want all URLs to redirect regardless of what content is on the english language site, you want something more like this:

/* 302! Language=it

or if you really do want to redirect just the landing page, you still need the ! (cf

/ 302! Language=it

If you give that a try and it doesn’t work, let me know!

That will cause all pages, even ones

Hi fool! thanks for the reply.
I had the rules inside the _redirects file.

Now I’ve placed your examples inside the netlify.toml file but during build it gives me this error:

Invalid netlify.toml file: Error while decoding file /opt/build/repo/netlify.toml: Near line 1 (last key parsed ‘’): bare keys cannot contain ‘/’

I’m a bit confused now in which syntax is correct for the netlify.toml file, I’ve also tried:

from = "/"*
to = “
status = 302
force = true
conditions = {Language = “it”}

with no luck, I get this error during the build:
Invalid netlify.toml file: Error while decoding file /opt/build/repo/netlify.toml: toml: cannot load TOML value of type string into a Go slice

The examples that @fool mentioned is for the _redirects file. Those examples will need to be converted to the structured format if you want to use them in your netlify.toml file.
This is how the redirect should look like:

from = "/*"
to = “”
status = 302
force = true
conditions = {Language = [“it”]}

For reference, this is mentioned in our netlify.toml reference doc.

Thanks @Dennis, now I don’t get the errors on build anymore, which is nice.
But still, no redirect is happening.

It works only if I use the country condition, not the language ones.

Hi @federicovezzoli can you please provide a link to the deploy that you are testing and the URL that you are testing with? Also does your browser have multiple languages set? Can you test with sending a single language and let me know if that works? Note that I don’t believe people should limit the number of languages, this is for debugging purposes.