htaccess域重定向奇怪的问题

时间:2014-04-04 15:16:23

标签: apache .htaccess redirect

我尝试将来自域example.com的所有请求重定向到example.com.pl,这似乎相当容易。

我拥有的是:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

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

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com.pl/? [R=301,NC,L]

但是我得到了 http://example.com/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/.pl/ 错误是"This web page has a redirect loop"

此规则捕获的其他域名被正确重定向。它必须与目标域是原始域+' .pl'这一事实有关。

1 个答案:

答案 0 :(得分:0)

以这种方式尝试:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://example.com.pl%{REQUEST_URI} [R=301,NE,L]

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