301 Domain Redirects
One of the most reused snippets of code I write is a bit of Apache configuration that I put in my .htaccess file to do Google-friendly 301 redirects. I typically use them for two purposes: First, to redirect traffic to my active site from other URLs that I own (sometimes my site is listed as jeffsiarto.com). And second, to kill the www in front of my domains (read more on the www debate).
301 redirects tell the browser that a page has moved permanently and will force search engines to update their records and drop the old URL—avoiding duplicate content problems.
Redirect traffic from an old domain to a new domain
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [r=301,NC]
Redirect traffic that uses the www subdomain
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]