Page 1 of 1

Help with .htaccess redirect

Posted: Sun Mar 15, 2015 9:18 pm
by netmaestro
Hi, I'm hoping someone skilled in web hosting issues can help with this. I have two domains, example.com and example.ca. The .com domain is meant to redirect to the .ca webspace in all cases. The .ca domain has an ssl certificate and is accessed via https://example.ca. Here's what I have right now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.ca/$1 [L,R=301,NC]
This seems to work fine in most cases, however there is a case that it's failing. If someone types https://example.com it doesn't redirect properly, they get taken to a page telling them it's unsafe to proceed. Of course, https://example.com doesn't exactly exist, https://example.ca does.

Can someone suggest a redirect that will catch https://example.com and change it to https://example.ca? I'm hoping this is possible without buying a second ssl certificate.

I really am quite a noob on this subject, thanks in advance for any help.

Re: Help with .htaccess redirect

Posted: Sun Mar 15, 2015 9:35 pm
by freak
After the page that says it is unsafe to proceed, does the redirect then work if you choose to proceed anyway?

I don't really know anything about redirection, but my guess would be that you need an SSL certificate also for the example.com domain. After all, the client can't really find out about the redirection (which happens at the HTTP level) until it has established a proper SSL connection with example.com. That is where the unsafe warning is coming from.

Re: Help with .htaccess redirect

Posted: Sun Mar 15, 2015 9:44 pm
by netmaestro
If you push on past the safety warning it loads the correct page from the .ca webspace (the .com domain has no webspace of its own, it's an addon) but the address bar shows https://example.com, which doesn't exist but the https portion has a stroke through it.

Re: Help with .htaccess redirect

Posted: Sun Mar 15, 2015 10:10 pm
by freak
As I said, you will definitely need two certificates, because the SSL stuff with example.com happens first before any redirection can take place. So you need a valid certificate for that domain. If it works after the warning, then you are probably good on the redirection itself.

See also: http://serverfault.com/questions/167395 ... ther-https

Re: Help with .htaccess redirect

Posted: Sun Mar 15, 2015 10:13 pm
by netmaestro
Ok thanks, I thought that might be the case. I'll get another certificate.

Re: Help with .htaccess redirect

Posted: Sun Mar 15, 2015 10:59 pm
by Dude
I don't know if you need to purchase another certificate, although you probably have by now? :)

Here's how I redirect "website.com" to "www.website.com" with my .htacess file. I'd assume you'd change the relevant bits in your own file to point your .com to your .ca? Don't forget that such redirects can also take a day or so to take effect (in my experience).

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} ^website.com [nocase]
RewriteRule ^(.*) http://www.website.com/$1 [last,redirect=301]