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

I'm a little bit lost with a redirection.

I want mysite.com, www.mysite.com and www.mysite.co.uk to redirect to mysite.co.uk.

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

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

And for mysite.com, I wrote this redirect to mysite.co.uk:

ServerName www.mysite.com
RewriteEngine on
RewriteRule ^/(.*) http://mysite.co.uk/$1 [L,R=301]

This way, I can make the redirection work properly from www.mysite.com to mysite.co.uk, but it doesn't work for mysite.com too mysite.co.uk (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

2 Answers 2

up vote 0 down vote accepted

In your config for www.mysite.com, add this;

ServerAlias mysite.com

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;

ServerAlias www.mysite.co.uk

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 http://httpd.apache.org 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.