【问题标题】:how do i use .htaccess to redirect different languages to different pages?我如何使用 .htaccess 将不同的语言重定向到不同的页面?
【发布时间】:2011-04-11 19:49:27
【问题描述】:

我正在尝试制作一个简单的 2 语言网站,我不熟悉 .htaccess,但找到了一个在线工具:http://www.htaccesstools.com/redirection-by-language/

我希望英语浏览器转到我的根文件夹的 index.html,而泰语浏览器转到一个子文件夹。

我从生成器得到的是:

RewriteEngine on
RewriteCond %{HTTP:Accept-Language} th [NC]
RewriteRule .* http://www.mysite.com/th/index.html [R,L]

这不起作用,我收到重定向循环/其他错误。我已经尝试将最后一行的 url 更改为相对的,但这并不影响它。

有什么帮助吗?

*确认一下,我的根文件夹中只有一个 .htaccess

【问题讨论】:

  • 您是否正在采取措施阻止 /th/index.html 再次被重定向?我记得,Apache 的规则往往是世袭的。 (但不要相信我的话。)
  • 不,我不知道该怎么做。如果你能提供帮助,那就太好了。欢呼

标签: html .htaccess mod-rewrite redirect


【解决方案1】:

在你的 .htaccess 文件中试试这个:

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(/th/index.html|.*\.(woff|ttf|svg|js|ico|gif|jpg|png|css|htc|xml|txt))$ [NC]
RewriteCond %{HTTP:Accept-Language} ^th [NC]
RewriteRule .* /th/index.html [R,L,QSA,NE]

【讨论】:

    猜你喜欢
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    相关资源
    最近更新 更多