Instead of writing custom snippets for php headers its faster to redirect website visitor to “his” language by using .htaccess rewriting rules (mod_rewrite should be enabled though and certain permissions allowed for you to change htaccess directives)
so, lets imagine you already have language support on website by entering corresponding language as first argument in url:
http://yourdomain/en/index/ for english speaking visitors http://yourdomain/fr/index/ for french speaking visitors
in order to redirect these visitors by default when they enter a site, you may write tricky cookies or PHP snippets that grab User Agent Language, but for me somehow this approach turned out to be cool enough in order not to make site engine not to support feature that is needed in one of 30 pages.
RewriteEngine on of course is already there since i already have user friendly url’s, so i add these lines to .htaccess
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ fr/index/ [L,R=301]
RewriteRule ^$ en/index/ [L,R=301]
First line detects “Accept-Language” header in user agent and if it is “fr*” for any french speaking visitor, i redirect him to french site on second line.
Third line is a fallback for default English language site.
IF you dont have friendly url’s but want to start having some right now, then just add RewriteEngine on on .htaccess file in your site root.
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ index.php/?language=fr [L,R=301]
RewriteRule ^$ index.php/?language=en [L,R=301]
Htaccess is a tricky thing, so you might need additional Options but that goes beyond this post. Cheers!


