views:

1260

answers:

4

Well I have a site that uses relative paths for all the URLs. I just added a shopping cart so the two or three checkout pages are using HTTPS instead of HTTP. My problem is that a user is mid way through checkout and clicks a link on the navigation or whatever it seems them to that page with HTTPS when it is a page that doesn't require it (and it some cases can't handle it because of external files e.g. GoogleMaps.js)

+1  A: 

you can try doing something like

RewriteCond %{SERVER_PORT} !^(80|8080)$
RewriteCond %{REQUEST_URI} !^(checkout|order|etc)$
RewriteRule ^(.*)$         http://yoururl$1

I'm not sure if it works because I didn't test it, but you could use the ideea of testing for {SERVER_PORT}. Hope it helps

andi
You answered this while I was typing my answer. I like yours better though!
Andrew G. Johnson
it's pretty much the same thing.actually, using %{HTTP_HOST}%{REQUEST_URI} like you did is more elegant :)
andi
Better not to rely on port numbers. Check if HTTPS is on (or off, if you want to force it on).
Scott
Yeah. Scott is probably right. I used port because I didn't know about %{HTTPS}.
andi
Agreed, %{HTTPS} is the thing to use here.
David Zaslavsky
+3  A: 

Actually surprised myself and hacked something together. Reroutes everything that isn't www.domain.com/checkout

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^(/checkout)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Andrew G. Johnson
A: 

You don’t need the additional RewriteCond directive to exclude /checkout/…:

RewriteCond %{HTTPS} on
RewriteRule !^checkout(/|$) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Gumbo
A: 

This is what I have in my .htaccess :

RewriteEngine On    
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

For some reason it is not working. Seems like it doesn't recognize https access through %{HTTPS} ?!

Amir E. Habib