Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule for Switching HTTPS back to HTTP

RewriteRule SWITCH HTTPS TO HTTP

         

the_wad

3:44 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



I can successfully switch to https when the url matches a certain pattern, but how do I switch the protocol back to http for other url patterns? Once I'm in https, I'm stuck in https.

The first rule below works successfully to switch to https:
RewriteEngine On
RewriteRule ^/shop_payment(.*) [%{SERVER_NAME}...] [L,R]

Below is my attempt to get back to http for a url pattern that is essentially not matching the above. I've tried many variations, including using! on the above url pattern.

RewriteCond %{REQUEST_URI} ^products(.*)$
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^/(.*)$ [%{SERVER_NAME}%{REQUEST_URI}...] [R=301,L]

Other info:
My rules are in my httpd.conf file, and this is a simple one server, one virtual host installation connecting to Tomcat. I'm using Apache v2.2

Thanks.

jdMorgan

12:12 am on Aug 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you were very close to me...

RewriteCond %{REQUEST_URI} [b]^/p[/b]roducts
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^/(.*)$ http://%{SERVER_NAME}[b]/$1[/b] [R=301,L]

I also trimmed out some superfluous stuff after "products" -- it wasn't needed, and the shorter version is entirely functionally equivalent.

Also, if this code is for use on one and only one server, then hard-coding the domain will run faster:


RewriteCond %{REQUEST_URI} ^/products
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301,L]

Jim