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

I have a SSL certificate installed and running well with Apache 2.2.14. Now, I want to restrict the use of https to just one directory, namely www.example.com/shop. If a user goes to https://www.example.com or any other URL but www.example.com/shop, I want to force http instead of https.

I'm running Wordpress on this site and can't for the life of me figure out how to write the correct rewrite rules for this (I bet simple) scenario. Any help appreciated!

share|improve this question
    
You may be interested in this: webmasters.stackexchange.com/a/28443/11628 –  Bruno Apr 29 '12 at 16:00

3 Answers 3

up vote 2 down vote accepted

Well, I can't think of any good reason to actively block the use of HTTPS, but this should do it...

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/shop [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]
share|improve this answer
    
Thank you, very helpful! –  John V. Apr 30 '12 at 8:06

A simple rewrite rule would be:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

You could also use is the SSLRequireSSL directive in the .htaccess file for that directory to completely bar access to that folder over HTTP even if the rewrite rule gets ignored for some reason.

P.S. I think you can use %{SERVER_PORT_SECURE} in place of %{HTTPS} above.

share|improve this answer
    
I recommend to use the static server name (e.g. www.example.com) instead of %{HTTP_HOST} in above rewrite rule. Mostly SSL certificates are bound to specific host names and so you can take care of using the correct host name. –  Jens Bradler Apr 28 '12 at 6:55

Couldn't you just use the SSLRequireSSL in the shop directory .htaccess and SSLDenySSL elsewhere?

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.