Tuesday, June 22, 2010

redirect http to https multiple domains

After the torture of trial and error I have devised a working .htaccess way to redirect http to https while having multiple domains, follow the steps below.

First task is to have the /secure directory secure with https, in this directory create the .htaccess and place this text:
RewriteEngine on
RewriteCond %{http_host} secure.domain.ca [or]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domain.ca/secure [L,R=301]

You can place this anywhere else that you want redirected (i.e other domains), basically users will try hitting the http and redirect to that domain with https!

Second is having the / domain not secure (if your certificate isn't *. users will get a warning, we don't want that), and it will have different subdomain in this example (www1). In the root directory place this in .htaccess:
RewriteEngine on
RewriteCond %{http_host} ^domain.ca [or]
RewriteCond %{http_host} ^www.domain.ca [NC]
RewriteRule (.*)  http://www1.domain.ca/

And now waiting to see if the mx records work...

No comments: