我需要从一个域到另一个域进行一些重定向:一些特定的重定向+一般规则:
具体重定向:
subdomain.example.com/ => example.com/subdomain/
subdomain.example.com/page1 => example.com/subdomain/page1
一般规则 - 应适用于未使用上述规则捕获的所有网址:
subdomain.example.com/* => example.com/*
以下是我现有的规则 - 问题是它们似乎是相互排斥的:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule /? http://example.com/subdomain/ [R=301,L]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
我究竟做错了什么
你有不正确的RewriteRule
模式,你应该用/?
包含^/?$
,否则它匹配所有的URL。
^
:开始行
$
:行尾
# first specific rule
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^/?$ http://example.com/subdomain/ [R=301,L]
# second specific rule
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^page1$ http://example.com/subdomain/page1 [R=301,L]