Thursday, February 01, 2007

htaccess 301 Redirects

Often times my tips are a little on the basic to intermediate level. I'd like to offer up a tip that is more on the upper end of the intermediate level in terms of importance, but actually pretty basic to accomplish.

Its the 301 Redirect.

Often times web sites or pages will be redirected from one to another, however, if you use the wrong type of redirect, the search engines might penalize you for duplicate content or not provide you the credit you deserve.

A simple area to consider is in setting up a domain. Often times when a domain is setup we don't think twice about whether the official domain is or

However, from the search engines perspective they are two different locations. If they both shuttle visitors to the same content then you might not get as good of a PageRank rating as you would like.

Plus if other people link to your site and use the non-www version and you consider your primary domain to include the www domain then you will not get full credit for the incoming links.

Solution - Setup a 301 Redirect

So all you need to do is setup a 301 redirect within your .htaccess file telling the search engines which domain is the primary and which one is just properly redirecting to the primary.

Now I came across this suggestion from SmartLabSoftware in their htaccess Tips.

They offer a simple additional line of code that you can add to your htaccess file.

I went with a variation on that theme that looks like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Basically, this will redirect my domain name without the www to my chosen primary domain with the www.

I could have just as easily have done this in reverse.

So now if someone links to my side without the www, I will get the linkback credit against the full domain!

Hello, More PageRank World!

No comments: