Forum Moderators: phranque

Message Too Old, No Replies

HTTPS to HTTP when not required. Not working exactly

         

nickCR

5:56 am on May 25, 2010 (gmt 0)

10+ Year Member



Hello All,

Basically the issue is the following:

I have this in my .htaccess located on the domain root (http://www.example.com)

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !admin(.*) [NC]
RewriteCond %{REQUEST_URI} !beta(.*)$ [NC]
RewriteCond %{REQUEST_URI} !members(.*) [NC]
RewriteCond %{REQUEST_URI} !images(.*) [NC]
RewriteCond %{REQUEST_URI} !templates(.*) [NC]
RewriteCond %{REQUEST_URI} !buyit(.*) [NC]
RewriteCond %{REQUEST_URI} !shoppingCart.php(.*) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Works great on the live site.

Does not work great with the beta site. If I go to the sub directory (beta) then I get the page and it loads up at first with the ssl enabled symbol then half way through the load this symbol changes to not secure.

I have checked the page and it's not that. In fact I found that if I comment each of those items the page in beta will load complete with the SSL symbol and stay that way. So these lines above are certainly affecting it but I don't understand why because I have beta in there as one of the directories to ignore.

Thank in advance, Nick

nickCR

6:10 am on May 25, 2010 (gmt 0)

10+ Year Member



I figured it out ... I guess while writing this I had an epiphany

Originally before the above I had this:

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/admin/ [NC]
RewriteCond %{REQUEST_URI} !^/members/ [NC]
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_URI} !^/templates/ [NC]
RewriteCond %{REQUEST_URI} !^/buyit/ [NC]
RewriteCond %{REQUEST_URI} !^/shoppingCart.php [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Following that I tried the first option I posted

Finally I tried this :

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !admin/
RewriteCond %{REQUEST_URI} !beta/
RewriteCond %{REQUEST_URI} !members/
RewriteCond %{REQUEST_URI} !images/
RewriteCond %{REQUEST_URI} !templates/
RewriteCond %{REQUEST_URI} !buyit/
RewriteCond %{REQUEST_URI} !shoppingCart.php(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Surely enough it worked. It's loading up perfectly fine now.

jdMorgan

3:02 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm a bit late to the party I'm afraid, but you could optimize that for performance in .htaccess.

RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^(admin|beta|members|images|templates|buyit)/
RewriteCond $1 !^shoppingCart\.php$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

List the "directories" in the second RewriteCond in order of most- to least-frequently requested for best performance.

The "exact string match" in the first RewriteCond is a bit faster than a regular-expressions match.

You could also combine the third RewriteCond with the second, but I left it separate because it's easier to read and maintain this way... This is a matter of 'style' mostly -- A trade off between efficiency and clarity.

Jim

nickCR

6:28 pm on May 25, 2010 (gmt 0)

10+ Year Member



jd thanks a lot for that :)

What you have provided is superb and I'll use that instead of what I'm using now.

I actually thought about how to do it like that last night after finding a few examples similar to what you posted. I just couldn't figure out how to adapt it accordingly.

Thank you again.