I currently have a site where I am using .htaccess to turn https on for certain sections of the site:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (evaluate/purchase*)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

There are several files starting with "purchase" that reside in the "evaluate" folder, and all of those need to be protected. So far, this works.

I now need to protect several other files and directories, however adding them as a rewrite condition doesn't seem to work:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (evaluate/purchase*)
RewriteCond %{REQUEST_URI} (another_dir/file.php)
RewriteCond %{REQUEST_URI} (please_secure_me.php)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

This isn't kicking up any 500's or anything, it just will only protect the files in the first condition. What am I doing wrong?

link|improve this question

25% accept rate
feedback

2 Answers

up vote 1 down vote accepted

IIRC, RewriteCond is an AND condition.

"If all conditions match, processing is continued with the substitution of the Substitution string for the URL."

What you're saying at the moment is (HTTPS off AND URI is this AND URI is this AND URI is this) which is incorrect as the URI cannot be 3 different things at the same time!

You want a combined AND/OR condition (HTTPS off AND (URI is this OR URI is this OR URI is this))

Try duplicating your rule:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (evaluate/purchase*)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (another_dir/file.php)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (please_secure_me.php)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 
link|improve this answer
This worked. Thank you. – Charles Chadwick Feb 9 '10 at 20:43
feedback

Actually just looking through the 2.2 docs, you may be able to this:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (evaluate/purchase*) [OR]
RewriteCond %{REQUEST_URI} (another_dir/file.php) [OR]
RewriteCond %{REQUEST_URI} (please_secure_me.php)
RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

If it works, it's a much more elegant solution.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.