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'm a little bit lost with a redirection.

I want, and to redirect to

In Apache, I wrote this for in order to redirect www to the root domain:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www
RewriteRule ^/(.*)$1 [L,R=301]

And for, I wrote this redirect to

RewriteEngine on
RewriteRule ^/(.*)$1 [L,R=301]

This way, I can make the redirection work properly from to, but it doesn't work for too (without the www) at the same time. Could someone tell me how to make all my redirections work in all cases?

share|improve this question
up vote 0 down vote accepted

In your config for, add this;


This will make the VirtualHost respond to that hostname too, and since the only configuration in that VirtualHost entry is to redirect, it will. For brownie points, you could also add in;


And ditch the RewriteRules in your first VirtualHost entry altogether.

share|improve this answer
Thanks, you made my day. – Guilhem Soulas Sep 4 '12 at 20:00

What about using the apache directive:




See for more information.

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.