我想强制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
访问权限排除在外。有人能告诉我我的规则有什么问题吗?
答案 0 :(得分:1)
:)
...
你忘记了“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
我最喜欢检查regexp的工具:
http://www.quanetic.com/Regex(别忘了选择ereg(POSIX)而不是preg(PCRE)!)