Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 want to forward a domain ( to another one ( which is located on another server. The problem is, this new server already hosts 2 domains ( and, and the redirection actually redirects to the other domain ( on this new server.

On the DNS of, I created a CNAME record from "www" to "".

What else do I have to do to make redirects to and not


share|improve this question
up vote 1 down vote accepted

You can add a ServerAlias to the vhost file:

I'm assuming that is the default domain that the server picks up.


You can see the list of vhosts your apache serves, as well as which one is default using

apachectl -S

If the default is '', then any requests that are determined to go to that server indicated by your CNAME that aren't correctly configured in the vhost, will direct to the default vhost.

Edit 2 added rewrite code.

Once you're sure that the ServerAlias is set up right and a request from '' is serving the files from '', you can make sure all traffic from gets properly 301-redirected (simply speaking: the URL changes in your browser, and search engins know this is a permanent change) using the following code (assumes you have mod_rewrite enabled) in the vhost file (or .htaccess):

<IfModule mod_rewrite.c>                                                                                                                                                     
RewriteEngine On                                                                                                                                                             

RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$1 [R=301,L]
share|improve this answer
Would that change the URL as well or the will remain? – Nicolas May 19 '11 at 16:47
It won't change the url unless you use mod_rewrite or mod_alias to redirect to – DTest May 19 '11 at 16:48
Could you provide me the code to do an actual forwarding. I do not want to appear in the addess but instead. Cheers. – Nicolas May 19 '11 at 16:50
added example rewrite. GL – DTest May 19 '11 at 17:06
Thank you for all your explanations. I put the rewrite code into the vhost file as I do already have a .htaccess file for the website. Thank you for your replies. Nicolas. – Nicolas May 20 '11 at 7:05

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.