Right now I redirect 100% of the time if someone does https://mysite.com

<VirtualHost *:443>
   ServerAdmin webmaster@mysite.com
   ServerName mysite.com
   ServerAlias www.mysite.com

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

However, now I want to conditionally redirect. If a user goes to https://mysite.com/abc/, 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.

link|improve this question
feedback

2 Answers

up vote 2 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:
- http://www.whoopis.com/howtos/apache-rewrite.html
- http://www.sitepoint.com/article/apache-mod_rewrite-examples/

link|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 https://mysite.com/foo/test/abcdef, 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 Zaslavsky Aug 29 '09 at 2:45
show 1 more comment
feedback

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

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

(edited)

link|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
feedback

Your Answer

 
or
required, but never shown

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