Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 If a user goes to or any other URL but, 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: – Bruno Apr 29 '12 at 16:00
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. 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


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.