Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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]
share|improve this answer
So you are saying without getting one for no www there's no way to redirect without the warning, right? –  Francisc May 19 '11 at 21:37
If 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. –  Seth Robertson May 19 '11 at 21:46
Thank you very much, Seth. –  Francisc May 19 '11 at 21:47
Google 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. –  Seth Robertson May 19 '11 at 21:49
I already accepted it. I'll take a look, thanks again. –  Francisc May 19 '11 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.