Monday, October 20, 2008

URL Re-writing

URL Rewriting with ASP.NET 2.0
How to implement URL Rewriting and Improve your SEO rankings.

Introduction

In this article, you will learn about URL Rewriting in ASP.NET 2.0. URL Rewriting was originally introduced by Apache as an extensions called mod_rewrite. The concept of URL rewriting is simple. It allows you to rewrite URL from those ugly URL into a better URL and hence it will perform better in SEO.

Most Search Engines will ignore those dynamic URL such as the one ended with querystring
e.g http://www.worldofasp.net/displayproduct.aspx?ID=10
Therefore if you like to have more hits and traffic from search engine, consider of rewriting all those querystring url into normal URL.

If you rewrite the URL above, you can actually rewrite it into more readable format
e.g http://www.worldofasp.net/product10.aspx.
or you can rewrite it to http://www.worldofasp.net/product/10.aspx.

Search Engine robot will think that your dynamic page is a normal page and therefore it will crawl your page and your page will have a better search results.
If you check all the page in Worldofasp.net or CodeProject.com, you can see that the web developer is using URL rewriting techniques.

Main

Microsoft .NET Framework 2.0 come with limited URL Rewriting Library support and you have to write your own URL Rewriting engine if you need complex URL rewriting for your website.


The simplest URL Rewriting that you can achieve in seconds is by copy and paste the code below to your global.asax file.

void Application_BeginRequest(Object sender, EventArgs e)
{
String strCurrentPath;
String strCustomPath;
strCurrentPath = Request.Path.ToLower();<BR
if (strCurrentPath.IndexOf("ID") >= 0)
{
strCustomPath = "/Product10.aspx";
// rewrite the URL
Context.RewritePath( strCustomPath );
}
}
As you can see from the code above, the URL Redirection is only limited to one rules. It will always redirect to one page called product10.aspx if it detects that your URL contains ID keyword.
Of course this one will not work if you want different Query String ID to redirect to different page or if you want to have different page redirection for different query string type.

To have a more complex URL Rewriting Rules, we can use Regular Expressions for implementing different redirection techniques.

Now, lets start writing some rules for your Redirection.
urlrewrites
rule
url>product/(.*)\.aspx
podcast directory
Bloglisting.net - The internets fastest growing blog directory

RSS Feed

Blog Directory & Search engine

Followers

About Me