目前我有:
Redirect 302 / http://www.example.com
虽然我仍然希望发生此重定向,但如果他们说,我不希望它重定向他们foo.mydomain.com
或该子域上的任何其他页面。
我怎样才能做到这一点?
要以这种方式更具体,您需要使用RewriteCond / RewriteRule
而不是一个简单的Redirect
指示。进行否定匹配(!
) for foo.mydomain.com
并执行重写。您可以使用 OR 组匹配多个子域(foo|other1|other2)
RewriteEngine On
# Redirect anything except foo.example.com, bar.example.com
RewriteCond %{HTTP_HOST} !^(foo|bar)\.example\.com$ [NC]
# Redirect to www.example.com, preserving the URI
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=302]
如果您只想重定向到根而不是通过附加整个 URI$1
,使用相同的RewriteCond
就这样做:
# Match and redirect everything to the root of www.example.com
RewriteRule ^. http://www.example.com/ [L,R=302]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)