这是我想要做的:
travel.xx.com => xx.com/travel
travel.xx.com/fun => xx.com/fun
travel.xx.com/page.htm => xx.com/page.htm
health.xx.com => xx.com/health
health.xx.com/food => xx.com/food
health.xx.com/page2.htm => xx.com/page2.htm
这是我的htaccess规则:
RULE SET NUM 1: //将subdomain.xx.com转换为xx.com/subdomain和subdomain.xx.com/WHATEVER转换为xx.com/subdomain/WHATEVER
RewriteCond %{HTTP_HOST} ^health.xx.com$ [NC]
RewriteRule ^(.*)$ http://xx.com/health/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^travel.xx.com$ [NC]
RewriteRule ^(.*)$ http://xx.com/travel/$1 [R=301,L]
RULE SET NUM 2: 将xx.com/subdomain/WHATEVER转换为xx.com/WHATEVER
RewriteRule ^(travel|health)(\/)([a-zA-Z0-9\&^\-\_\!\:\,\.\']+)?$ $3 [R=301,L]
规则集第一和第二个单独工作正常。当我把它们放在一起时,规则2停止工作并重定向到根。
有人能告诉我这里缺少什么或者给我一个解决方案吗?
谢谢,
答案 0 :(得分:0)
而不是显示3条规则,您只需要这两条规则做同样的事情:
RewriteCond %{HTTP_HOST} ^(health|travel)\.(xx\.com)$ [NC]
RewriteRule ^/?$ http://%2/%1/ [R=302,L,NE]
RewriteCond %{HTTP_HOST} ^(health|travel)\.(xx\.com)$ [NC]
RewriteRule ^(.+)$ http://%2/$1 [R=302,L,NE]
请务必将此代码保留在其他规则之前。