简体   繁体   English

mod_rewrite REQUEST_URI混淆

[英]mod_rewrite REQUEST_URI confusion

I want to force ssl access on an entire site, except for the following pages: 我要在整个网站上强制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/

Force ssl : 强制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]

However neither of the /cards or /locations_and_contacts and any of the pages are being excluded from being served with ssl access. 但是, /cards/locations_and_contacts以及任何页面都不会从ssl访问中排除。 Can someone tell me what's wrong with my set of rules? 有人可以告诉我我的这套规则有什么问题吗?

:) :)

... ...

You forgot the "OR" directive. 您忘记了“ OR”指令。 Here's what should work (and maybe you've forgotten the QSA directive in the redirect as well (maybe not)): 这是应该起作用的方法(也许您也忘记了重定向中的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]

Two hints: 两个提示:


Please try to use the RewriteLog directive: it helps you to track down such problems: 请尝试使用RewriteLog指令:它可以帮助您RewriteLog此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp: 我最喜欢的用于检查正则表达式的工具:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!) http://www.quanetic.com/Regex (请不要忘记选择ereg(POSIX)而不是preg(PCRE)!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM