Force HTTPS only for one Directory

Fix it!!

Force HTTPS only for one Directory

Postby wh33t » Thu Sep 16, 2010 6:18 pm

Hello all

I am trying to force HTTPS for one directory only on my site. The shopping cart page. So far I have this.

Code: Select all
ErrorDocument 404 /404.php

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /basket/
RewriteRule ^(.*)$ https://www.website.com/basket/$1 [R,L]


Which works great, however once a user visits the HTTPS basket page every link they view after that has HTTPS in the URL. I suppose that's because of the links are written with out the full domain name and protocol ("/webpage.html").

So now I would like to have another rule that say anyone viewing a directory or page that isn't in the /basket/ should be sent to regular HTTP.

It would be a bonus too to force http://domain.com to be rewritten to http://www.domain.com as well. Thanks a lot. Hope to get some replies in the right direction very shortly!
wh33t
 
Posts: 10
Joined: Sat Mar 01, 2008 11:00 am

Re: Force HTTPS only for one Directory

Postby newelement » Mon Sep 20, 2010 6:13 am

I'm having a similar issue, but I think I'm close. I can get the HTTP to HTTPS working but not back to HTTP.

Code: Select all
RewriteEngine On

RewriteBase /
      
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^checkout/?$ https://www.domain.com/checkout/ [R=301,L]

RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^checkout/?$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond $1 !^index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php [L]
newelement
 
Posts: 6
Joined: Fri Feb 13, 2009 7:45 am

Re: Force HTTPS only for one Directory

Postby newelement » Fri Sep 24, 2010 6:26 pm

Does anybody have any insight on this?
newelement
 
Posts: 6
Joined: Fri Feb 13, 2009 7:45 am


Return to Security with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron