Forum Moderators: phranque

Message Too Old, No Replies

Rewrite to www except for https connections

         

encyclo

1:56 am on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm a bit stuck on what seems like a very simple problem.

I want to redirect all requests from example.com to www.example.com, except for any requests for the resource which are secure (https) connections.

My site is available under:

http://www.example.com/

and under a shared SSL certificate:

https://ssl.myhostingprovider.net/example.com/

So I don't want anything redirected when the connection is secure.

I tried the following code in the .htaccess:

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTP_HOST} !^www.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]

But this gives an infinite loop. Where am I going wrong?

Thanks!

coopster

1:19 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think you want to get rid of the
[OR]
on your first rewrite condition .
RewriteEngine on 
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301, L]

jdMorgan

1:38 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Definitely... You need the default 'AND' behaviour here.

Jim