.htaccess永久重定向(301)问题

时间:2011-08-18 13:32:01

标签: .htaccess redirect

我正在尝试将我的.fr网址的www和非www版本重定向到.com网址。 www工作,但我不能让非www工作。知道为什么非www重写不起作用吗?

RewriteCond %{HTTP_HOST} ^www\.domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

完成.htaccess

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.44

RewriteEngine on
RewriteLogLevel 0
LogLevel debug 
RewriteBase /


RewriteCond %{HTTP_HOST} ^(www\.domain\.fr|domain\.fr)$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain.org [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain.net [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain.de [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.domain.eu [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteRule ^nl/js/(.*)$ /js/$1 [L, NC]
RewriteRule ^fr/js/(.*)$ /js/$1 [L, NC]
RewriteRule ^en/js/(.*)$ /js/$1 [L, NC]

RewriteRule ^nl/images/(.*)$ /images/$1 [L, NC]
RewriteRule ^fr/images/(.*)$ /images/$1 [L, NC]
RewriteRule ^en/images/(.*)$ /images/$1 [L, NC]

还有一堆像这样的重写规则

RewriteRule ^nl/news.asp$ n_news.asp [R]
RewriteRule ^fr/news.asp$ f_news.asp [R]
RewriteRule ^en/news.asp$ e_news.asp [R]

1 个答案:

答案 0 :(得分:1)

根据我的理解(基于您的htaccess),您要做的就是将 ANY 配置的域名重定向到www.domain.com

在这种情况下,请尝试使用此单一规则,而不是针对您拥有的每个TLD(co.uk,.org,.eu等)的单独规则:

RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

所以不是www.domain.com的任何内容都会重定向到它。