By: admin

301 redirects and the .htaccess file

June 30, 2006

Share:

For anyone who is serious about search engine optimization knowing about 301 redirects is a MUST.  I searched and searched all over for the “bottom line-tell me how to do it” examples of the 301 redirects and found the information confusing. 

SO, I want to share with you the bottom line code you will need to implement into the .htaccess file.

FIrst, the code to get your non www’s always redirecting to the www’s is as follows:

Here€™s the code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

(Make sure your Apache installation has mod_rewrite enabled.)

As long as your Apache installation has mod_rewrite enabled then you should be able to use this fix on almost any host.

Second:  If you have any old page urls that are being replaced by new search engine friendly ones, but do not want to lose your page rank then here’s the code for that:

redirect 301 /old/oldurl.html http://www.newurl/new.html

MAKE SURE you DO NOT include the http://www.whatever.com  ONLY USE whats after the .com starting with the / or it will not work!  Also make sure to only put ONE space in between everything!

There you go!  That is as simple as it gets…or at least as I can make it!

Remember why we do the 301 redirect:

Mainly for Google.  Google does not like a bunch of error pages and if you have a lot of 404 error pages that do not exist anymore (maybe after doing a redesign, or introducing new SEF naming conventions) then its harder for Google to crawl and you can lose the page rank the page has.  With the 301 redirects you do not lose PR and you will not have to worry about duplicate content issues with your www and non www’s.  That alone is worth doing it!

Written by admin on June 30, 2006

Follow me: