I have domain like, example.com where I want https://example.com to be redirected to https://www.example.com/

Does anyone have any recommendation on how to set this up?

I tried setting up a apache virtual host for example.com on the same server and added a redirection rule. But, https://example.com does not redirect. Instead, files get served for the request.

I also get the error _default_ VirtualHost overlap on port 443, the first has precedence when starting apache.

link|improve this question
1  
Just to check the obvious. Are you certain that your certificate is valid for both names? – Zoredache Mar 22 '11 at 7:06
feedback

2 Answers

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.examples.com/$1 [R=301,L]

Put that in a .htaccess in the root of the Document_Root for that domain

link|improve this answer
I don't get it. This seems to say "if we are on http (NOT https) and the host is not www.example.com, then change the URL to examples.com";. That is not the question. – jmvidal Sep 14 '11 at 19:15
feedback

The following should do it:-

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/(.*) https://www.%{HTTP_HOST}/$1 [NC,R,L]
</IfModule>

Just make sure you have a LoadModule for mod-rewrite in there before this lot.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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