0

我有一个使用 Wordpress 的 WPML 插件处理语言的 3 种语言的调查社区。不幸的是,语言检测只能通过 php 工作。我想使用 htaccess,因为它更快并且用户不会注意到延迟。

设置如下:

community.netigate.net/ (English, International)

community.netigate.net/de/ (German)

community.netigate.net/sv/ (Swedish)

我尝试了不同的方法,发现最好的方法是

http://tech-blog.borychowski.com/index.php/2009/03/htaccess/redirect-according-to-browser-language-mod-rewrite-and-http_accept_language/

由于大多数用户是德国人或瑞典人,我希望“英语”只是标准的后备语言。设置可能是这样的:

CHECK IF 语言是瑞典语,然后重定向到瑞典子页面
CHECK IF 语言是德语,THEN 重定向到德语子页面
ELSE 使用英语作为后备

不幸的是,下面的解决方案最终会导致无休止的重定向?我错过了什么?

## Language Detection

#The 'Accept-Language' header starts with 'sv'
#and the test is case-insensitive ([NC])

RewriteCond %{HTTP:Accept-Language} ^sv [NC]

#Redirect user to /sv/hauptseite address
#sending 301 (Moved Permanently) HTTP status code

RewriteRule ^$ /sv/ [L,R=301]

#The 'Accept-Language' header starts with 'de'
#and the test is case-insensitive ([NC])

RewriteCond %{HTTP:Accept-Language} ^de [NC]

#Redirect user to /de/hauptseite address
#sending 301 (Moved Permanently) HTTP status code

RewriteRule ^$ /de/ [L,R=301]

#For every other language (including English :)) use English

RewriteRule ^$ / [L,R=301]
4

2 回答 2

0

添加另一个重写条件,检查重定向是否已经发生

## Language Detection

#The 'Accept-Language' header starts with 'sv'
#and the test is case-insensitive ([NC])

RewriteCond %{HTTP:Accept-Language} ^sv [NC]

#If not already redirected
RewriteCond %{REQUEST_URI} !^/sv/ [NC]    # ADDED

#Redirect user to /sv/hauptseite address
#sending 301 (Moved Permanently) HTTP status code

RewriteRule ^$ /sv/ [L,R=301]

#The 'Accept-Language' header starts with 'de'
#and the test is case-insensitive ([NC])

RewriteCond %{HTTP:Accept-Language} ^de [NC]

#If not already redirected
RewriteCond %{REQUEST_URI} !^/de/ [NC]    # ADDED

#Redirect user to /de/hauptseite address
#sending 301 (Moved Permanently) HTTP status code

RewriteRule ^$ /de/ [L,R=301]

#For every other language (including English :)) use English

RewriteRule ^$ - [L]    # MODIFIED
于 2013-08-15T08:08:08.220 回答
0

这一行在这里:

#For every other language (including English :)) use English
RewriteRule ^$ / [L,R=301]

正在重定向//,导致重定向循环。你根本不需要这条线。

于 2013-08-15T08:09:35.380 回答