如果另一个RewriteCond出现故障,请注意几个OR-RewriteCond指令

时间:2013-05-29 14:44:02

标签: mod-rewrite

我有以下配置,

RewriteCond %{HTTPS} !^on$ [nocase,ornext]
RewriteCond %{HTTP_HOST} !^www\. [nocase,ornext]
RewriteCond %{HTTP_HOST} !\.com$ [nocase]
RewriteRule ^(.*)$ https://www.acme.com/$1 [redirect=301,last]

目的是如果请求不是HTTPS,则重定向到规范URL,也不以www开头。或以.com结尾。 为了与开发人员引擎无缝兼容,如果%{HTTP_HOST}包括dev.internal左右,我想排除所有这些指令。在这种情况下,应立即跳过RewriteRule。由于三个OR的优先级高于(隐式)AND,我想知道如何以及在何处放置dev.internal异常...... 谢谢你的建议!

// edit:hmm ...如果OR具有更高的优先级,则不应

RewriteCond %{HTTP_HOST} !internal\. [nocase]
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [nocase,ornext]
RewriteCond %{HTTP_HOST} !^www\. [nocase,ornext]
RewriteCond %{HTTP_HOST} !\.com$ [nocase]
RewriteRule ^(.*)$ https://www.acme.com/$1 [redirect=301,last]
那么工作呢?

1 个答案:

答案 0 :(得分:0)

如果我对ornext的理解是正确的,那么您的方式应该有效(其他人可以确认吗?)。

这是另一种方式,如果你不想依赖它:

RewriteCond %{HTTP_HOST} internal\. [nocase] # If it's an internal host...
RewriteRule .* - [skip=1]                    # ... skip the next rule (and leave the URL unchanged)

RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [nocase,ornext]
RewriteCond %{HTTP_HOST} !^www\. [nocase,ornext]
RewriteCond %{HTTP_HOST} !\.com$ [nocase]
RewriteRule ^(.*)$ https://www.acme.com/$1 [redirect=301,last]