Language redirection with mod_rewrite

I have a website that is offered in 7 languages.

I want to be able to redirect the user based on the browser language only when the user visits the home page. This is intended for ease of use when it comes to organic traffic. I need this redirect to apply only to the main page, since the site also sends mail programs specific to each language, and they will not work if the user is redirected.

Each language is also a subdomain. e.g. www.site.com for English and de.site.com for German. The Mailer URL will look something like this: www.site.com/home/login?query=string

I would like to do this with a .htaccess file, if possible.

Can anyone suggest an understanding?

Thank.

+3
source share
2 answers

Since you only want to redirect to your home page, you can do this (suppose www.xyz.com is your home page)

RewriteCond %{HTTP:HOST} www.xyz.com  // user visiting default
RewriteCond %{HTTP:Accept-Language} ^de [NC] // browser language German
RewriteRule ^$ de.xyz.com [L,R=301] // R=302 if you need temporary redirect

http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-according-to-browser-language-mod-rewrite-and-http_accept_language/

+7
source

This is working out Rizwan's answer , too much for editing or comment (I tried).

, ( www.xyz.com, de.xyz.com ..). ( ):

RewriteCond %{HTTP:HOST} www.xyz.com         // Visit to default domain.
RewriteCond %{HTTP:Accept-Language} ^de [NC] // Browser language German.
RewriteRule ^$ http://de.xyz.com/       [L,R=301]

RewriteCond %{HTTP:HOST} www.xyz.com
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteRule ^$ http://it.xyz.com/       [L,R=301]

# etc. for your other 5 languages

:

  • R=301 - , , , . , R=302.
  • Accept-Language: , . , de;q=0.5, en;q=0.9. , . .
  • RewriteRule, ^$ , " ". , Apache , .htaccess [source]. ( VirtualHost / , ^/$.)
+1

All Articles