Url Rewriting in Asp.net
Url rewriting is usefull for SEO.It provides us SEO friendly url.
Suppose you want to rewrite the following url
http://www.urlrewrite.com/products.aspx?category=books
http://www.urlrewrite.com/products.aspx?category=DVDs
http://www.urlrewrite.com/products.aspx?category=CDs
to the following
http://www.urlrewrite.com/products/Books
http://www.urlrewrite.com/products/DVDs
http://www.urlrewrite.com/products/CDs
Search engine will take this at three different pages.
For this ,you have to follow the following steps..
Step 1 : Add reference Intelligencia.UrlRewriter
Step 2 : Add following code to Web.config file
<configuration>
<configsections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
</configSections>
<system.web>
<httpmodules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<rewriter>
<rewrite url="~/Products/(.+)" to="~/Products.aspx?category=$1"/>
</rewriter>
</configuration>
To avoid you having to hard-code every URL in your web.config file
<rewrite url="~/Products/(.+)" to="~/Products.aspx?category=$1"/>
Now , you will see the following urls in address bar
http://www.urlrewrite.com/products/Books
http://www.urlrewrite.com/products/DVDs
http://www.urlrewrite.com/products/CDs
Url Rewriting in Asp.net
Reviewed by vishal
on
11:46 AM
Rating: