我有.htaccess文件,如:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?market/(.*)$ http://market.example.com/$1 [L,R=301]
RewriteRule ^/?buddies/(.*)$ http://buddies.example.com/$1 [L,R=301]
RewriteRule ^/?bazaar/(.*)$ http://bazaar.example.com/$1 [L,R=301]
它在市场子目录中运行良好。它重定向到子域。但是,其他2个子目录存在问题。
其他2个子域的错误:
The page isn't redirecting properly
我该怎么做才能解决这个问题?
答案 0 :(得分:5)
这是因为RewriteCond
仅适用于下一个RewriteRule
。您的最后两条规则针对所有主机执行,包括buddies
和bazaar
,并导致重定向循环。
您需要以下规则:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?market/(.*)$ http://market.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?buddies/(.*)$ http://buddies.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteRule ^/?bazaar/(.*)$ http://bazaar.example.com/$1 [L,R=301]