I’ve setup a web site on:
https://foo.com
and I would like it if traffic from the following urls:
http://foo.com
http://www.foo.com
https://www.foo.com
would be automatically redirected there. That is if someone types one of the the lower three URLS in their browser, I would like it to immediately change the URL displayed to https://foo.com and I want to receive a HTTPS request on https://foo.com on the server, just like if the person had typed https://foo.com.
Which of the methods of achieving this is best? I’m using Apache.
Also the SSL certificate is signed for foo.com not www.foo.com, is it possible to achieve the redirect from https://www.foo.com without issuing a certificate warning? Or do I need to get a second certificate for www.foo.com?
All of the non SSL sites will have no problem redirecting using a rewrite in either your vhost file or your .htaccess file (assuming you have *.foo.com a server alias for foo.com).
You’ll need a certificate for each of the the miss-spelled ssl urls or they’ll get certificate errors when people try to connect to them. Once that’s done, you can redirect them.
Assuming the server aliases are setup and you have mod_rewrite enabled, here is the rewrite rule you need: