【问题标题】:Language redirection with mod_rewrite使用 mod_rewrite 进行语言重定向
【发布时间】:2018-01-28 21:52:59
【问题描述】:

我对 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]

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

【问题讨论】:

    标签: .htaccess redirect mod-rewrite seo translation


    【解决方案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]
    

    【讨论】:

    • 您的代码正在打开 html 索引,甚至没有重定向到索引 php。没有返回服务器错误,但没有其他任何内容
    • 立即尝试使用be 默认语言
    • 无论在哪个国家,GET 值都坚持(是)。我想我可能可以使用 php 标头 Location 或类似的,并在页面内容打开之前重定向
    • 我通过使用 htaccess 和 PHP 的组合让它工作。现在我的网站在自动翻译时自动重定向,例如:example.com/fr example.com/se 等。不必创建新页面。只需要处理其他目录。不过感谢 U 4 尝试 2 的帮助,你很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多