Monday, December 8, 2008

URL redirect and rewrite complete guide

URL redirection is been a real night mare for many webmasters. While many webmasters would like to solve canonical issue in their website by URL redirecting and without knowing the exact phenomena they are the worst hit by this URL redirection cloud.
People may argue that Google had come out with an option in webmaster tool to suggest which version to be taken care, either www version or non www version. But I would say Google is not the only search engine in the world, there are many notable SEs including yahoo and Live. And of course canonical issue is not the only issue to be solved. When you are trying to move a page to another page and one domain to another domain you need to know all these kinda stuffs in depth.

I have tried my level best to produce a comprehensive guide for URL redirection and implementing them via URL rewriting. Why you need URL Redirection,
You can use it in several situations, including:
• to redirect an old website to a new address
• to setup several domains pointing to one website
• to enforce only one version of your website (www. or no-www)
• to harmonize a URL structure change
Here comes the URL redirection types and its explanation.

301 Redirection:
URL redirection is a permanent redirection method. When you try to redirect you content permanently, please go with that. This is actually a function of web server that redirects a visitor to a new page from the old page and response a server code that the page has permanently moved. This is the most search engine friendly way of doing URL redirection. URL redirected using this method will get all the credibility and link juice from the older domain / old page most probably.

302 Redirection:
This is a temporary URL redirection method. When URL redirected using this method, web server that redirects visitors to the new page from the old page to the new page and returns a server code as the page has been temporarily moved. And there is a high chance of getting your search engine ranking getting lapsed in this method. So go for this method only when required.

Meta Redirect:
This is a clide side function using meta refresh tag. In earlier days search engines believed this method as spam technique as many spammers used this techniques to redirect the keyword rich domain / page to a new domain / page Though search engines have advanced in their algorithum its better you keep in mind all search engines and avoid this type (Meta Refresh) of URL redirection.

Want to read this from the mouth of Big boss Big G? They have given the article in a romantic way here.

URL Redirection Implementation using URL rewriting:
There are two methods to implement this URL redirection. We can do this either by server side URL redirection method or client side URL redirection methods.

Client Side redirection can be done using the following methods.
Meta Refresh using Meta Refresh tag
JavaScript Redirection

Server side redirection can be done using the following methods,
301 Redirection in PHP
301 Redirection in ASP(VB Script)
301 Redirection in ASP (JScript)
301 Redirection in ASP.Net (#C)
301 Redirection in Cold Fusion
301 Redirection in JSP / JAVA
301 Redirection in CGI / PERL

You can find the above mentioned URL redirection how to implement guide here.

Canonical issue is the most common issue one can find in the website. we can solve this using htacess file. Open a notepad copy paste the below mentioned code save the file as ".htacess". (Please note that there is no file extension). And upload this in root directory, Its almost done. Before making this done, make sure you change to your domain name from domain.com. This is the sample file that works perfectly with apache servers.

If you want to redirect from the non www to the www:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

If you choose to instead redirect the www to the non www:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://domain.com/$1 [R=301,L]

Share your thoughts in comments!

4 comments:

Raghavan said...

Nice post Mercy :))

Anonymous said...

Hi Mercy,

What does "canonical issue".

Sorry to trouble you as always,
Chaitanya

Mercy said...

@ Raghavan Thanks :)

@ Chaitanya - No issues what so ever! Canonical issue is your website having two different versions. Say for example, http://www.domain.com/ and http://domain.com/ which is actually the same domain but treated as two sepeated domains by search engines.

To explain you further I give you some more examples, which point the same page but still tretaed by search engines as different pages,
http://www.domain.com/
http://domain.com/
http://www.domain.com/index.php
http://domain.com/default.asp

Complete SEO Guide said...

Let it be clear that it isn't magic, it does take time and great effort, but if you follow these clear guidelines you will instantly increase your odds of achieving a top ranking within the major search engines such as Yahoo, Google and MSN.

Post a Comment