我想在整个站点上强制使用 ssl
访问,但以下页面除外:
www.example.com/loans_and_lines/home_loans.html www.example.com/cards
www.example.com/cards/international-ministries.html
www.example.com/cards/international-ministries/donation-3.html
www.example.com/locations_and_contacts/
强制 ssl
:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/personal/loans_and_lines/home_loans\.html
RewriteCond %{REQUEST_URI} !^/cards/$
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries\.html
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries/donation\-3\.html
RewriteCond %{REQUEST_URI} !^/locations_and_contacts/$
RewriteRule (.*) https://www.example.com$1 [R=301,L]
但是 /cards
或 /locations_and_contacts
和任何页面都没有被排除在 ssl
访问服务之外。有人可以告诉我我的规则集有什么问题吗?
最佳答案
:)
...
您忘记了“OR”指令。这是应该起作用的(也许您也忘记了重定向中的 QSA 指令(也许不是)):
# Force SSL
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/personal/loans_and_lines/home_loans\.html [OR]
RewriteCond %{REQUEST_URI} !^/cards/$ [OR]
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries\.html [OR]
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries/donation\-3\.html [OR]
RewriteCond %{REQUEST_URI} !^/locations_and_contacts/$
RewriteRule (.*) https://www.example.com$1 [QSA,R=301,L]
两个提示:
请尝试使用RewriteLog
指令:它可以帮助您追踪此类问题:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
我最喜欢的正则表达式检查工具:
http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg(PCRE)!)
关于linux - mod_rewrite REQUEST_URI 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8511431/