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

Right now I redirect 100% of the time if someone does

<VirtualHost *:443>

   RewriteEngine on
   RewriteRule (.*) http://%{HTTP_HOST} [L,R=permanent]

However, now I want to conditionally redirect. If a user goes to, then I want to use https; otherwise redirect.

How do I do this? I tried reading the docs, but just couldn't find what I needed.

I am using Apache on Ubuntu Linux.

share|improve this question
up vote 3 down vote accepted

Try adding a RewriteCond (Rewrite Condition) before the RewriteRule. I would try writing something like this:

RewriteCond %{REQUEST_URI} !^.*(abc).*$ [NC]

Here is some additional reading if this doesn't help:

share|improve this answer
Thus, what you offered seems to make sense on the surface, but I get this when reloading Apache RewriteCond: bad argument line '!^%{HTTP_HOST}/abc'. I am trying to read the links you sent me to see if there is any more hints. – Joel Marcey Aug 29 '09 at 0:13
It is probably just my syntax that is wrong. I don't have a machine to test it on myself at the moment. Please post the correct syntax when you figure it out. Good luck! :) – Thus Aug 29 '09 at 0:19
Well, I tried different syntax that seemed to work --- RewriteCond %{REQUEST_URI} !^.*(abc).*$ [NC] --- Thanks for your help and trying to point me in the right direction. – Joel Marcey Aug 29 '09 at 0:26
I'm happy to hear that I could help. I edited the syntax of my answer to your corrected version. – Thus Aug 29 '09 at 0:30
This answer will also use HTTPS for things like, which I think is not what you (Joel) wanted. And anyway, it's way overkill to add on a RewriteCond just to test against the request URI. (Not downvoting, though... it does technically work) – David Z Aug 29 '09 at 2:45

I'll reproduce the answer I gave you on the Slicehost forums:

RewriteRule !^/abc/ http://%{HTTP_HOST} [L,R=permanent]


share|improve this answer
I had to remove the space between the ! and the ^ to get this to work for me, otherwise I was getting "bad flag delimiters". – philfreo Jan 21 '10 at 0:32

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.