Add the following lines to the .htaccess
file at the root of your old domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
This will direct everything from your olddomain.com
to newdomain.com
. The $1
ensures that "everything after the root" is preserved exactly as it was before. The response code 301
means "permanent redirect" - it tells the browser making the request "we have moved". The L
means "this is the last statement in the processing" - so no further rules get processed for something that matched the RewriteCond
itions.
You have to make sure that mod_rewrite
is enabled. This usually involves checking the httpd.conf
file, making sure the correct line is uncommented, and restarting your server.
More info at http://www.orderofbusiness.net/blog/redirect-old-domain-to-new-domain-via-htaccess/ or https://support.google.com/webmasters/answer/93633?hl=en - or any of thousands of other sites...