Change Domain and Keep All Links with .htaccess

The following RewriteRule lives in the .htaccess file at olddomain.com and tells any request coming in to that domain to swap olddomain.com out and replace it with newdomain.com. This includes ANYTHING after the trailing slash, like a direct link to a previous post. So http://olddomain.com/this/direct/link gets sent properly to http://newdomain.com/this/direct/link

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

The important part is the [R=301] which sends a 301 (Permanent) Redirect header.
That tells search engines that the page has moved permanently.

affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.