jump to navigation

Simply 301 redirect March 7, 2006

Most webmasters think that domain.com is actually similar to www.domain.com since the files are located on the same location, and these addresses are just pointed to the same files.

Search engines look at them differently and considers them duplicate pages and may affect these pages’ PR (Page Rank), eventhough they are logically stored on same location. To make the point clearer we can simply say that www is just a special case subdomain of the main domain, like anyother subdomain created for a different purpose mail, pop3, blog etc.

To be able to let the spiders know that these are not duplicate entries we may need a way to inform these spiders that they are actually the same. how?

There are a couple of ways these are being done, but to go into it’s technicalities, what we actually need to do is to permanently redirect one to the other and inform the spider we did it.

Example: Suppose you might want to redirect all requests from http://domain.com/ to http://www.domain.com/

Why are we doing these? Since most search engines consider the www and non-www addresses to be duplicate entries, we would want to tell the visitors/spiders while visiting our site that the content it is looking for has been moved to a new location. This is the best way to let the spider know that we have not created any duplicate page/entry.

What is 301 Redirect? The 301 Redirection is described in RFC2616 “The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs“. And it is advised that search engines should forget the redirecting address and save the address pointed to by the redirection as the preferred address.

Okay, okay, so how do I do it? To be able to have the server reply to certain web requests when a visitor/spider visits your site, you should be able to setup the 301 Redirect depending on your Hosts Web Server. There are several methods to do but has certain disadvantages and advantages, though all provide the same results. For this purpose, we will deal with Apache and .htaccess file. If you are using a Linux box, with Apache Server installed, you will need to create, or edit the .htaccess file found on sites root, in my case it is

/home/myuser/public_html/.htaccess

Now that you already have the basic idea what is happening, let’s try playing with one domain. Supposing i have a domain named dhundee.com and i wanted to redirect visitors of a certain http://www.dhundee.com/old.html to http://www.dhundee.com/new.html.

Here’s what the .htaccess file should look like.

Redirect 301 /old.htm http://www.dhundee.com/new.html

now supposed we wanted to redirect the whole site.

Redirect 301 / http://www.newdomain.com

suppose we wanted to redirect http://dhundee.com to http://www.dhundee.com, although the instruction above is possible, most domains are setup to work on the same location, wherein www.dhundee.com is hosted on the same place as dhundee.com. It might cause you undesirable result to use Redirect 301 / http://www.dhundee.com. I added here a different set of instructions to make it work.

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

These set of instructions will force visitors from http://dhundee.com to be redirected to http://www.dhundee.com

There are couple more tricks you can play with using .htaccess though i hope i was able to help some of those who are currentlywondering how to these is done.

Comments»

1. wrencelot - March 25, 2006

thank god.. been searching for this kind of redirection because my domain http://mydomain.com has a page rank of 0 while http://www.mydomain.com has a pagerank of 2..

nice blog

*domain name withheld for security purposes

2. mia-carmel - November 8, 2006

Hi!

I’m using this code in my htaccess instead of that:

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

Which do you think is more accurate? ๐Ÿ™‚

3. Randy - November 10, 2006

hi mia,

it think you created a loop on that code, note that you are redirecting to the http://www.domain.com, but you tried to grab the destination on the filter (^\www.domain\.com) which will cause the redirection to loop indifinitely and will simply produce an error.

I suggest youร‚ย omit the www on the Condition.

Good Luck!

4. mia-carmel - December 18, 2006

thanks so much for the tip! ๐Ÿ™‚

5. Kabarkada - December 19, 2006

not a problem, how’s baguio? ๐Ÿ˜€