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

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.

share|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
add comment

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

share|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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.