Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have domain like, where I want to be redirected to

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

I tried setting up a apache virtual host for on the same server and added a redirection rule. But, 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
Just to check the obvious. Are you certain that your certificate is valid for both names? – Zoredache Mar 22 '11 at 7:06
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$$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, then change the URL to";. That is not the question. – jmvidal Sep 14 '11 at 19:15

The following should do it:-

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

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

share|improve this answer

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, put the following line:
Redirect /

share|improve this answer

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.