简体   繁体   中英

mod_rewrite REQUEST_URI confusion

I want to force ssl access on an entire site, except for the following pages:

  • 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 :

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. Can someone tell me what's wrong with my set of rules?

:)

...

You forgot the "OR" directive. Here's what should work (and maybe you've forgotten the QSA directive in the redirect as well (maybe not)):

# 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:

# 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)!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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