Redirect based on language with PHP?

I have a website, one in English and one in Portuguese. I’d like to, when a user whose browser language is Portuguese accesses the English website, they should be redirected to the respective Portuguese version.

i.e.
If user enters https://www.example.com, he should be taken to https://www.example.com.br/
If they enter https://www.example.com/product-1, take them to https://www.example.com.br/product-1-pt (notice that the URL path is also different)
and so on…

I’m really stuck. Can anybody suggest an approach for this?

Thanks!

$_SERVER['HTTP_ACCEPT_LANGUAGE']

will give you the browser language. You can then use PHP’s header() function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.