从重定向和子域与浏览器语言的htaccess基地 [英] redirect from and to subdomain with htaccess base on browser language

查看:110
本文介绍了从重定向和子域与浏览器语言的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]

这篇关于从重定向和子域与浏览器语言的htaccess基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆