How can I redirect from https://mysite.com to https://www.mysite.com? The SSL certificate is bought for www.mysite.com and shows a warning if accessed without www.
1 Answer
It will be too late. Users will have already seen the error message and had to accept it by the time the redirect happens unless you get another certificate. The previous answer has that problem.
Ignoring that, you can create a named based virtual host on port 443, set up ssl on that, and then have it rewrite. Note that instead of using your existing certificate (which will generate an error) you can have a cheap, valid certificate under mysite.com on that virtual host so that you don't get an error prior to the redirect.
NameVirtualHost *:443
<VirtualHost *:443>
ServerName myname.com
SSLCertificateFile /etc/ssl/apache2/server.crt
SSLCertificateKeyFile /etc/ssl/apache2/server.key
SSLEngine on
RewriteEngine on
RewriteRule ^/(.*) https://www.mysite.com%{REQUEST_URI} [L,R]
</VirtualHost>
-
So you are saying without getting one for no www there's no way to redirect without the warning, right?– FranciscMay 19, 2011 at 21:37
-
1If they type https : //mysite.com, no. On the plus side, you don't need ultimate double plus premium certificates for mysite.com. Whatever the cheapest you can find (some are free) which will get the user redirected to the real website which can have whatever level of certification necessary is fine. You might want to investigate the very expensive wildcard certificates, but I don't think they allow mysite.com and www.mysite.com, just www.mysite.com and support.mysite.com and foo.mysite.com, etc. May 19, 2011 at 21:46
-
1Google pointed me to (randomly, never seen them before) digicert which claims they can support a single wildcard cert for the top level and the subdomains. Is this really the same cert or just multiple certs in the same container? Check it out. Please accept if you like the answer. May 19, 2011 at 21:49
-