2017-08-20 48 views
1

对于mod_rewrite,我完全无能为力,所以我很乐意为您提供帮助。我只希望Apache根据检测到的国家语言重定向我的主页。我的PHP是以多种语言自动翻译的,我试图避免因为搜索引擎优化而将相同的确切网站与子域和域相乘 - 但看起来谷歌并没有如此先进,没有其他选择。使用mod_rewrite进行语言重定向

例如

mysite.com to: 
mysite.com/index.php?lang=nl for holland 
mysite.com/index.php?lang=fr for france 
and for no specified country code just to: 
mysite.com/index.php?lang=be 

mysite.com/?lang=nl wwould also be fine 

我也很乐意听到更好的建议。 我想没有更迭

RewriteCond %{HTTP:Accept-Language} ^nl[NC] 
RewriteRule ^index\.html /index\.php?lang=nl [QSA,NC,L] 
RewriteCond %{HTTP:Accept-Language} ^fr[NC] 
RewriteRule ^index\.html /index\.php?lang=fr [QSA,NC,L] 

我刚开服务器错误以下 - 无法找到一个确切的情况下,可以帮助

回答

1

与尝试:

RewriteCond %{HTTP:Accept-Language} ^(nl|fr) [NC] 
RewriteRule ^(index\.html)?$ /index.php?lang=%1 [QSA,NC,L] 
RewriteRule ^(index\.html)?$ /index.php?lang=be [QSA,NC,L] 
+0

你的代码打开HTML索引,甚至没有重定向到索引PHP。没有服务器错误返回,但没有其他的东西 – alexis

+0

现在尝试用'be'默认语言 – Croises

+0

GET值坚持(无论)在哪个国家。我想我可以在页面内容打开之前使用php头文件位置或类似的重定向 – alexis