我需要从一个域重定向到另一个域:一些特定的重定向+一般规则:
特定重定向:
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]
我做错了什么
答案 0 :(得分:1)
您的RewriteRule
模式不正确,您应将/?
与^/?$
括起来,否则它会与所有网址匹配。
^
:行首
$
:行尾
# 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]