使用mod_rewrite进行语言重定向



当涉及到mod_rewrite时,我完全一无所知,所以我很乐意得到任何帮助。我只是希望 Apache 根据检测到的国家/地区语言重定向我的主页。我的PHP正在自动翻译成多种语言,由于SEO的原因,我试图避免将相同的确切站点乘以子域和域 - 但看起来Google还没有那么先进,别无选择。

例如

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]

我刚刚收到服务器错误 - 找不到可以提供帮助的确切案例

尝试:

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]

最新更新