为什么我的 .htaccess <If></If> 之后的规则被忽略了?
Why are rules after my .htaccess <If></If> ignored?
我是 运行 一个 WordPress 网站,我想将某些域的 http 重定向到 https,所以我有这些 .htaccess 规则 (Apache 2.4):
<If "%{HTTP_HOST} in { 'secure.mydomain.com', 'ssl.mydomain.com' }">
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</If>
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
这适用于非 https 域(例如 www.mydomain.com). But the WordPress rules are not being applied to https://secure.mydomain.com or https://ssl.mydomain.com。当我使用这些域时,我收到 404 错误。如果我删除 IF 语句,我不会收到 404 错误。这几乎与如果 apache 认为 WordPress 规则包含在 else 语句中。
所以,一个简单的问题。这些规则有什么问题?
CBroe 的评论让我走上了正确的道路。 According to this blog、RewriteCond
在 <If>
块内不受支持。
我需要重写规则,让它只使用 RewriteCond
,或者它只使用 <If>
。像这样:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.mydomain\.com [OR]
RewriteCond %{HTTP_HOST} ^ssl\.mydomain\.com
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
或者这个:
<If "%{HTTP_HOST} in { 'secure.mydomain.com', 'ssl.mydomain.com' } && %{HTTPS} == 'off'">
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</If>
我是 运行 一个 WordPress 网站,我想将某些域的 http 重定向到 https,所以我有这些 .htaccess 规则 (Apache 2.4):
<If "%{HTTP_HOST} in { 'secure.mydomain.com', 'ssl.mydomain.com' }">
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</If>
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
这适用于非 https 域(例如 www.mydomain.com). But the WordPress rules are not being applied to https://secure.mydomain.com or https://ssl.mydomain.com。当我使用这些域时,我收到 404 错误。如果我删除 IF 语句,我不会收到 404 错误。这几乎与如果 apache 认为 WordPress 规则包含在 else 语句中。
所以,一个简单的问题。这些规则有什么问题?
CBroe 的评论让我走上了正确的道路。 According to this blog、RewriteCond
在 <If>
块内不受支持。
我需要重写规则,让它只使用 RewriteCond
,或者它只使用 <If>
。像这样:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^secure\.mydomain\.com [OR]
RewriteCond %{HTTP_HOST} ^ssl\.mydomain\.com
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
或者这个:
<If "%{HTTP_HOST} in { 'secure.mydomain.com', 'ssl.mydomain.com' } && %{HTTPS} == 'off'">
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</If>