Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 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} 
share|improve this answer
    
This worked. Thank you. –  Charles Chadwick Feb 9 '10 at 20:43

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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