Conditional https redirect to http depending on URL? (Apache)
13,837
Solution 1
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/
Solution 2
I'll reproduce the answer I gave you on the Slicehost forums:
RewriteRule !^/abc/ http://%{HTTP_HOST} [L,R=permanent]
(edited)
Related videos on Youtube
Author by
Joel Marcey
Updated on September 17, 2022Comments
-
Joel Marcey over 1 year
Right now I redirect 100% of the time if someone does https://mysite.com
<VirtualHost *:443> ServerAdmin [email protected] 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.
-
Joel Marcey over 14 yearsThus, 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.
-
Mateusz Kowalski over 14 yearsIt 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! :)
-
Joel Marcey over 14 yearsWell, 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.
-
Mateusz Kowalski over 14 yearsI'm happy to hear that I could help. I edited the syntax of my answer to your corrected version.
-
David Z over 14 yearsThis 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 aRewriteCond
just to test against the request URI. (Not downvoting, though... it does technically work) -
philfreo over 14 yearsI had to remove the space between the
!
and the^
to get this to work for me, otherwise I was getting "bad flag delimiters".