Point the new domain to the existing server with a new DNS entry. Then add the following lines to .htaccess in the root directory of the Web site:
RewriteRule ^(.*)$ [newdomain.com...] [R=permanent,L]
This reads "If the hostname in the requested URL is not [newdomain.com,...] rewrite the URL using [newdomain.com...] as the hostname, attach the requested URI, and return the resulting new URL, along with a 301-Moved Permanently server response code to the requestor. This is the Last RewriteRule to be processed for this request."
A browser will then re-request the desired page using this updated URL, as supplied by your server.
The above will rewrite all requests for [oldomain.com...] to [newdomain.com....] It will also rewrite [oldmain.com...] and [newdomain.com...] to [newdomain.com....] You can change the behaviour with respect to "www" as desired, by including or excluding the "www\." in the RewriteCond and the "www." in the RewriteRule.
The above can also be used in the httpd.conf configuration file with minor adjustments. Query strings will be preserved. More info [httpd.apache.org].
That's about it - it's not very difficult to do, but I suggest you test it on a production server or at least during the time of least site traffic!
Search engines will see the 301-Moved Permanently response returned by the server, and update their database to show the new URL in their search results. Anyone using a browser to access the site will see the URL in their address bar update to the new URL as well. You will need to "manually" ask that your listings in ODP, Yahoo, and other human-edited directories be updated.
[edited by: jdMorgan at 7:40 am (utc) on Oct. 30, 2002]