The goal is to have every page (minus one folder) of a site redirect to https. I've discovered the following does not do that. The one folder contains a subdomain. Let's call it mahogany.com.

Edit: Modify rules

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.site1\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} ^site1\.mobi [NC,OR]
RewriteCond %{HTTP_HOST} !^mahogany\.com [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

If someone types site1.mobi or www.site1.mobi into their browser, apache with the above in the document root htaccess will not redirect.

What is wrong with the above? Is a line for mahogany.com needed to exclude it?

1 Answer 1


The default logical operator for RewriteCond is "and"; the HTTP_HOST can't be both of those so the condition will never be satisfied.

Try this:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.site1\.mobi$ [NC,OR]
RewriteCond %{HTTP_HOST} ^site1\.mobi$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Also, you mentioned a directory exception, but I don't see one in there. You can add one with an extra RewriteCond or by changing your RewriteRule condition:

RewriteRule ^excepted/location/.* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • Thanks Shane. Trying it out now. Did you forget ( & ) in the line 4 of the first code? Originally it was (.*)
    – David C
    Jan 13, 2013 at 23:35
  • What about adding this condition: RewriteCond %{HTTP_HOST} !^mahogany.com [NC] and adding ,OR to the previous rule?
    – David C
    Jan 13, 2013 at 23:54
  • @DavidC No, I didn't forget them; you weren't using them so I removed them. And yes, adding that and adding OR to the other hostname will make it apply to all 3 of those hostnames. Jan 14, 2013 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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