mod_rewrite REQUEST_URI混乱

时间:2011-12-14 20:49:04

标签: linux apache mod-rewrite ssl

我想强制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访问权限排除在外。有人能告诉我我的规则有什么问题吗?

1 个答案:

答案 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)!)