从重定向和子域与浏览器语言的htaccess基地
问题描述:
我需要重定向我的用户在他们的语言主页基地。
我想我已经用
的RewriteCond%{HTTP:接受语言}
但我想不通。
我最后一次尝试:
I need to redirect my users in homepage base on their language.
I think I've to use
RewriteCond %{HTTP:Accept-Language}
but I can't figure out.
My last try:
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule .* http://mydomain.com [R,L]
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule .* http://en.mydomain.com [R,L]
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule .* http://fr.mydomain.com [R,L]
但是,这产生一个死循环。
But this generate an infinite loop.
文件夹结构
- 的htdocs / index.php文件 - > mydomain.com
- 的htdocs / EN / index.php文件 - > en.mydomain.com
- 的htdocs / FR / index.php文件 - > fr.mydomain.com
答
您需要确保主机是不是已经指向正确的地方:
You need to make sure the HOST isn't already pointing to the correct place:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule .* http://mydomain.com [R,L]
RewriteCond %{HTTP_HOST} !^en.mydomain.com$ [NC]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule .* http://en.mydomain.com [R,L]
RewriteCond %{HTTP_HOST} !^fr.mydomain.com$ [NC]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule .* http://fr.mydomain.com [R,L]