Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Canada

asked on

Rewriting URL

Hi All,

   I want to rewrite anything (root or subfolder) of the following domain (as an example):  I have other rewrite rules that I don't want to conflict with for the shopping cart.

http://www.test.com to http://test.com
and https://www.test.com to http://test.com

   I screwed up on my SSL and didn't realize I should've requested www.<domain>.com.  In IE it is coming up invalid certificate when I goto www.<domain>.com

Thanks - Zack
Avatar of Graham N.
Graham N.
Flag of United Arab Emirates image

Create/add to your .htaccess the following, replacing the domain name with yours.

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI} [R=301,L]

Open in new window


Please note these must be at the top of your .htaccess / rewrites - or else it won't work
Avatar of Zack

ASKER

Hmmm for some reason the top works but the https doesn't.
Ok try this instead:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) http://test.com%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST}  www.test.com
RewriteRule (.*) https://test.com%{REQUEST_URI} [R=301,L]

Open in new window

Avatar of Zack

ASKER

We're making progress lol.

It works on firefox but not on IE.  Is there some sort of stupid security thing in IE that you know of?
What does it do on IE?

And which version of IE?
Avatar of Zack

ASKER

it doesn't do anything it loads the url as usual disregarding the htts rewrite but the http works fine
ASKER CERTIFIED SOLUTION
Avatar of Graham N.
Graham N.
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zack

ASKER

Ok I understand what's happening with IE.  It's popping up an invalid SSL cert (because the SSL cert isn't good for www.  Once you acknowledge the invalid cert the rewrite does work.  

I appreciate your help!
Thanks Zack