1

Is there a way to redirect an user depending on is browser locale ?

For instance, I'd like to redirect to a page called index.en.html all users who doesn't have their browser locale set to French.

Could I do this with Apache and .htaccess ?

joschi
  • 21,387
  • 3
  • 47
  • 50
Boris Guéry
  • 516
  • 1
  • 6
  • 20

3 Answers3

3

Well looking at the documentation I found the MultiViews option.

Options MultiViews
AddLanguage fr .fr
AddLanguage en .en
<IfModule mod_negotiation.c>
     LanguagePriority fr en
</IfModule>
Boris Guéry
  • 516
  • 1
  • 6
  • 20
2

You should be able to match the environment variable %{HTTP_ACCEPT_LANGUAGE} or the HTTP header Accept-Language (with %{HTTP:Accept-Language}) for fr or fr-fr.

joschi
  • 21,387
  • 3
  • 47
  • 50
1

You can use mod_rewrite and test for the Accept-Language header. For example:

RewriteCond %{HTTP:Accept-Language} en-us
RewriteRule ^(.*)$ /en-us/$1 [L]

Better yet, take a look at mod_negotiation

http://httpd.apache.org/docs/2.2/content-negotiation.html

Dan Andreatta
  • 5,454
  • 2
  • 24
  • 14