301 Redirect in .htaccess
301 Redirects using .htaccess plays an important role both in keeping your site clean and organized as well as a solid SEO practice.
301 redirects are not as complicated as they may seem. First lets go over why you might want to use one.
1. Sites should redirect all URLs associated with their domain which do not start with “www” (example: “http://cheese.com”) to the same pages on your their domain that start with “www” (example: “http://www.cheese.com”). This is referred to as a canonical redirect. The reason this is so important is because search engines can’t tell if the non-www version of your domain is really a different site, or not, than the www version of your domain. And, if other webmasters link to your site, you can’t can’t control whether or not they link to your site with the www or not.
2. If you decide to move the content of a page of your site to a new URL. You may do this simply because you are improving the site layout, or you may do it because you are moving to a new domain name.
The 301 redirect is seen as a “permanent move” of the content while a 302 redirect is seen as a “temporary move” of the content. For SEO purposes you should NEVER use a 302. I have made that mistake several times, I used it for exactly the purpose it was intended for and suffered search engine penalty’s because of it.
You can redirect all non-www traffic to all www URLs, with the following Mod Rewrite code:
RewriteEngine on
RewriteCond %{HTTP_HOST} yourdomain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
RewriteRule ^(.*) http://www.yourdomain\.com/$1 [L,R=301]
To simply move one URL on your site to another use the following code:
redirect 301 /old/old.htm http://www.you.com/new.htm
Don’t add “http://www” to the first part of the statement - place the path from the top level of your site to the page. Also ensure that you leave a single space between these elements.
redirect 301 (the instruction that the page has moved)
/old/old.htm (the original folder path and file name)
http://www.you.com/new.htm (new path and file name)
