Forum Moderators: phranque
This site has a shopping cart and an order form page, and I would like to take advantage of the host's secure certificate for the order form. So on the shopping cart page (http://www.example.com/cart.php) I have the Checkout link going to [host.com...] which encrypts the page.
I would like to rewrite all requests to example.com to www.example.com, so I created an .htaccess file that looks like this:
# Redirect non www.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.co.nz
RewriteRule (.*) http://www.example.co.nz/$1 [R=301,L]
This works fine, but when a user goes to the order form page the URL gets rewritten from [host.com...] to http://www.example.com/orderform.php
Of course this breaks the SSL, so I decided I only want to do the rewrite on non-https URLS. I did some research and found several people saying to add the line:
RewriteCond %{SERVER_PORT} !^443$
So I added this line just before the RewriteRule but that didn't seem to do anything.
I asked my hosting company and they suggested replacing the resently added line with:
RewriteCond %{HTTPS} !^on$
So I tried this but it still doesn't work, the rewrite is still happening.
Does anyone have any ideas on how I can get this to work? I only want to do the rewrite on http and not on https URLs.
Next, it says "redirect everything that is *not* exactly www.example.co.nz to www.example.co.nz".
Why not change the Condition to say "redirect when request is only for example.co.nz" instead?
I assume that when you use host.com and example.com in your example that you really do mean that two different domain names are involved.
# Redirect non www.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.co.nz [NC]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ http://www.example.co.nz/$1 [R=301,L]
And yes, example.com and host.com are two different domain names.