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

I want to forward a domain (old.com) to another one (new.com) which is located on another server. The problem is, this new server already hosts 2 domains (new.com and other.com), and the redirection actually redirects to the other domain (other.com) on this new server.

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

What else do I have to do to make old.com redirects to new.com and not other.com?

Cheers,
Nicolas.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You can add a ServerAlias to the new.com vhost file: http://httpd.apache.org/docs/2.2/mod/core.html#serveralias

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

EDIT

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

apachectl -S

If the default is 'other.com', then any requests that are determined to go to that server indicated by your CNAME that aren't correctly configured in the new.com 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 'www.old.com' is serving the files from 'new.com', you can make sure all traffic from www.old.com 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                                                                                                                                                             

# START DOMAIN REDIRECTS
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://new.com/$1 [R=301,L]
# END DOMAIN REDIRECTS
</IfModule>  
share|improve this answer
    
Would that change the URL as well or the old.com 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 old.com to new.com –  DTest May 19 '11 at 16:48
    
Could you provide me the code to do an actual forwarding. I do not want old.com to appear in the addess but new.com 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 new.com website. Thank you for your replies. Nicolas. –  Nicolas May 20 '11 at 7:05
add comment

Your Answer

 
discard

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.