5,699,997 members and growing! (20,281 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Using URL rewriting to make money from google and search engines

By ropel

Easy way in asp.net to do MOD URL base from a table in the database
C#, VB, Windows, .NET, ASP.NET, VS.NET2003, VS2005, Visual Studio, Architect, Dev

Posted: 24 Dec 2006
Updated: 24 Dec 2006
Views: 16,885
Bookmarked: 22 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 1.84 Rating: 2.37 out of 5
3 votes, 50.0%
1
1 vote, 16.7%
2
0 votes, 0.0%
3
1 vote, 16.7%
4
1 vote, 16.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

MODURL The Easy Way:

Package Contents:

  • URL Rewriter sln
  • Sample Web Project
  • Table Scripts
  • WebConfig File
  • SQL Scripts to create the stored procedure and database tables

You can create a URL rewriting component for asp.net.

The two site examples are:

Inital Problem:

Need a way to create nice URLS that search engines like for a content page. The goal of this was to be able to add content pages to a site, and automatically have the URL rewritten and pull from a DB.

The content site has an article summary page and an article detail page. Without URL rewriting the links as the search engine would see them are

http://bongofdestiny.com/GenericContentHandler.aspx?ContentID=35
http://bongofdestiny.com/GenericContentHandler.aspx?ContentID=33

or

http://www.collegecupcakes.com/index.aspx?CurrentImageID=211
http://www.collegecupcakes.com/GenericContentHandler.aspx?ContentID=6

Couple reason we want to change this:

  • Search Engines like words
  • It is not apprant to the user what the link is.
  • If you email the link, it may be truncated in the email.

Look how much better these URLS look:

http://www.collegecupcakes.com/Carol-211-Fun.aspx
http://www.collegecupcakes.com/Party-With-No-Hangover.aspx

Or

http://bongofdestiny.com/Tenacious-D-Explosivo-Video.aspx
http://bongofdestiny.com/Tenacious-D-Song-Lyrics.aspx


That is the goal of this project

NOTE: much thanks to Scott Mitchell from 4GuysFromRolla.com. He created the base set of code that does the hard work. I just extended it to work with a database.

This is the original article this is based on:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp

Now, lets see how to do this:

Step 1:

Add a referece to the URLWriter.dll to your asp.net project (1.0 or 2.0 doesn't matter). It is already compiled and ready to go in the download.

Step 2:

Add the following to your web.config. This tells asp.net to send the request through the URLwriter etc

<configSections>
<!-- The <configSections> element must contain a <section> tag for the <RewriterConfig> 
 section element. The type of the section handler is RewriterConfigSerializerSectionHandler, 
which is responsible for deserializing the <RewriterConfig> section element into a 
RewriterConfig instance... -->
  <section name="RewriterConfig" 
           type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
</configSections>

Data base connection to look up the URLS in a table

</appSettings>
<add key="MODURLDB" 
 value="Data Source=[YourSQLServer];Initial Catalog=[DataBaseName];User ID=[YourUserID];Password=[YourPassword]"/>
</appSettings>

This tells asp.net what to use for the httpmodules

<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules>

(There is a sample web.config in the download for this source code

Step 3:

Create the tables in the database using the scripts URLWriterDBTableScripts.sql
This creates 2 tables and stored procedures The stored procedures are called by the URLWriter.dll

The page table is "PageMod" which lists the "LookFor" and "SendTo". When a request is made, the http handlers will look for the URL in the dataset, and if it finds it, it sends it to the "sendTo". If it doesnt find it, it passes the request on normally.

This creates 2 tables:

PageMod: holds the "LookFor" & "SendTo" columns for the urlrewriter engine
PageContentLive: This table holds content for the site. Notice the "PageMod" column, and the keywords, description
This is a template table, so you can create a page that has a list of the links, to the content, and display the links to the user.
On trick is to have a trigger on the "On Insert" event of a record, to auto populate the records in the PageMod table.

Step 4:

Set the connection string in the web.config file for the URL Rewriter
That is the basic setup. If you want to look at the code, have at it. Let me know if there are any changes that would make it better.


Now here is was you need to put into the table to test: The syntax must be exact:

When the request comes in for:

http://bongofdestiny.com/Tenacious-D-Lyrics-Kyle-Quit-The-Band.aspx

or

http://www.collegecupcakes.com/Carol-211-Fun.aspx

It is sent to

http://bongofdestiny.com/GenericContentHandler.aspx?ContentID=43

or

http://www.collegecupcakes.com//index.aspx?CurrentImageID=211

So in the table your would have

[SAMPLE LOOK FOR ROOT] 
~/Tenacious-D-Lyrics-Kyle-Quit-The-Band\.aspx
or
~/Carol-211-Fun\.aspx 

(The final slash before the .aspx is so the regular expression engines can quick look for it.

[SAMPLE SEND TO ROOT]
~/GenericContentHandler.aspx?ContentID=43
or
~/index.aspx?CurrentImageID=211 

So that is the basics of how the thing works. This is my first article, so please let me know if it all works.

Source code information:

In the source code,

RewriterConfiguration.cs
GetConfig
This is where the settings are grabbed from the database

This is the data access component to access the database
MODDALC.cs

Appconfig setting:
MODURLDB


Let me know if this helps and what we can do to extend the functionality

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ropel



Location: United States United States

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
GeneralFor Simplest Way of writing URL RewritingmemberDotNetGuts11:40 24 Jul '08  
GeneralThanksmemberGh0stman5:48 16 Jan '07  
GeneralWhat the hell is the use of thatmemberThe Pain Killer21:01 24 Dec '06  
GeneralRe: What the hell is the use of thatmemberHarry Cruz0:59 25 Dec '06  
GeneralRe: What the hell is the use of thatmemberropel18:05 25 Dec '06  
GeneralRe: What the hell is the use of thatmemberJeff Bowman18:20 25 Dec '06  
GeneralRe: What the hell is the use of thatmemberropel18:19 25 Dec '06  
GeneralRe: What the hell is the use of thatmemberdarrenmm1:53 26 Dec '06  
GeneralRe: What the hell is the use of thatmemberDoug K. Wilson9:58 26 Dec '06  
GeneralRe: What the hell is the use of thatmemberdarrenmm10:38 26 Dec '06  
GeneralRe: What the hell is the use of thatmemberropel14:24 4 Jan '07  
GeneralRe: What the hell is the use of thatmemberLord Delacroix21:12 9 Mar '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Dec 2006
Editor: Chris Maunder
Copyright 2006 by ropel
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project