2

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.

1
  • 1
    Just to check the obvious. Are you certain that your certificate is valid for both names?
    – Zoredache
    Mar 22, 2011 at 7:06

3 Answers 3

1
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

1
  • 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, 2011 at 19:15
0

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.

0

While you can use Apache rewrite engine to do that, it exists a simpler and more efficient solution: use the 'redirect' directive.

On the virtual host serving https://example.com, put the following line:
Redirect / https://www.example.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .