Language based redirects not working on production, but working on dev

This is pretty simple, I’m replacing the language redirection mechanism on a client’s website. Before it was JS based and now I’m exploring Netlify Redirects for that.

Here is the _redirects file:

## Created with gatsby-plugin-netlify
/404/  /pt/404/  301!  Language=pt
/about/  /pt/about/  301!  Language=pt
/contacts/  /pt/contacts/  301!  Language=pt
/  /pt/  301!  Language=pt
/privacy/  /pt/privacy/  301!  Language=pt
/services/  /pt/services/  301!  Language=pt
/work/  /pt/work/  301!  Language=pt
/404.html  /pt/404.html  301!  Language=pt

This is built using the Gatsby Netlify Plugin, so we can automatically create every redirect for every page and language. This is working great when using netlify dev. But on the actual production link, it’s not working. The site in question is https://sketic.com.

I read a bunch of topics related to this and not a single one had useful info, for me at least. If I manually specify the accept-language to use a single language (pt) it still doesn’t work. Anyway, it works great with the netlify dev server, it works as expected and redirects browsers with the PT language to the PT pages.

I’m lost here. Also on the Netlify dashboard redirects are processed correctly without errors. Tried different browsers, DNS providers even and different internet connections. Can this be related to some edge caching issue? It’s the only difference to my local netlify environment.

Any help is appreciated.

Update:

Guess it’s the same old problem. Only works when there is a single language on the browser.

curl -I -H 'Accept-Language: pt' https://sketic.com works and redirects to /pt
curl -I -H 'Accept-Language: pt,en' https://sketic.com doesn’t work

Netlify Dev
curl -I -H 'Accept-Language: pt' http://localhost:8888 works
curl -I -H 'Accept-Language: pt,en' http://localhost:8888 works

Any special reason why multi language works on Netlify Dev but not on production?

Could you share an example curl that doesn’t work? Seemed to work well to me:

$ curl -H "accept-language: pt" -v https://sketic.com/404 -o /dev/null
> GET /404 HTTP/1.1
> Host: sketic.com
> User-Agent: curl/7.70.0
> Accept: */*
> accept-language: pt
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
[...]
< Location: /pt/404/

What we don’t handle well right now are the preference/quality settings on languages, which most browsers set, as well as multiple languages.

Perhaps you could instead use country redirects which work better? Swap our your language=pt for country="pt,br" . It isn’t perfect - some people who prefer Portuguese browse from elsehwere, and some people in Portugal would set a different language - but it is the best thing we have today to try to satisfy your use case until a rearchitecting of our redirects (which is in progress!) lands to better enable the language-based redirects.

I’ll be using country redirects then. Thanks for the help!

1 Like

We have a lot of problems with this. Please fix this issue!!!

hi existo, can you be a bit more specific and maybe share which redirects aren’t working for you? i want to try and understand the problem a bit more and see if we have some suggestions for you.