Jeff Siarto - Web Designer

301 Domain Redirects

One of the most reused snip­pets of code I write is a bit of Apache con­fig­u­ra­tion that I put in my .htac­cess file to do Google-​​friendly 301 redi­rects. I typ­i­cally use them for two pur­poses: First, to redi­rect traf­fic to my active site from other URLs that I own (some­times my site is listed as jeff​siarto​.com). And sec­ond, to kill the www in front of my domains (read more on the www debate).

301 redi­rects tell the browser that a page has moved per­ma­nently and will force search engines to update their records and drop the old URL—avoiding dupli­cate con­tent prob­lems.

Redi­rect traf­fic 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]

Redi­rect traf­fic that uses the www sub­do­main

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

tagged: ,

Comments are closed.

Recommended

Also of Interest