IIS7 And URL Rewrite Reveals The Tricks Of Heavy Hitter Blog Sites

Have you ever wondered how blog and other advertising sites create an unending stream of URL's that contain the title? For example, our blog uses a trick called URL Rewrite, an add-on for IIS7. With this tool, you use regular expressions to create a filter that parses the info for you and redirects it to another page that can use that data to fill in the blanks.

 

For example: You can have a bot / SEO friendly URL like

http://www.esourcedevelopment.com/BlogPosts/3548/Windows_7_upgrade_horrors

which will actually be rewritten as:

http://www.esourcedevelopment.com/ShowRealPost.aspx?id=3548?title=Windows_7_upgrade_horrors

The URL that IE and Firefox show in the browser address space is the same as the first one requested, but the page actually displayed is the second one.

 

Setting up IIS7 to handle URL Rewrite

  • Go to IIS Manager
  • Select “Default Web Site”
  • In the Feature View click “URL Rewrite“
  • In the “Actions” pane on right hand side click on “Add rules…”
  • In the "Add Rules" dialog, select the "Blank Rule" and click "Ok"

Now you must define the actual rewrite rule. In the URL rewrite module, a rewrite rule is defined by specifying four required pieces of information:

  • Name of the rule;
  • Pattern to use for matching the URL string;
  • Optional set of conditions;
  • Action to perform if a pattern is matched and all conditions checks succeed.

Naming a rule
In the “Name” text box enter a name that will uniquely identify the rule, for example: ”Rewrite to article.aspx”.

Defining a pattern
In the “Pattern” text box enter the following string:

^blogposts/([0-9]+)/([_0-9a-z-]+)

This string is a regular expression that specifies that the pattern will match any URL string that meets the following conditions:

  • Starts with the sequence of characters “blogposts/”.
  • Contains one or more numeric characters after the first “/”.
  • Contains one or more alphanumeric or “_” or “-” characters after the second “/”.

Notice that certain parts of the regular expression are within parentheses. These parentheses create capture groups, which can be later referenced in the rule by using back-references.

Defining an action
Since the rule that we are creating is supposed to rewrite the URL, choose the “Rewrite” action type that is listed in the “Action” group box. In the “Rewrite URL:” text box, enter the following string:

ShowRealPost.aspx?id={R:1}&title={R:2}

 

This string specifies the new value to which the input URL should be rewritten. Notice that for the values of the query string parameters we used {R:1} and {R:2}, which are back-references to the capture groups that were defined in the rule pattern by using parentheses.

 

Now your actual page can decipher the QueryString values for ID and / or for title to search your database and display the article in question.

 

The entire tutorial on this setting can be found at http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

 

This site features a lot of 'how-to' information on IIS and is invaluable for any web developer.

Bookmark and Share DotnetKicks dotnetshoutout

Comments

1/18/2010 5:26:39 PM #

craftsman sears

Thank nice post

craftsman sears United States | Reply

3/20/2010 9:06:18 AM #

trackback

How to display a random image on another website

How to display a random image on another website

eSource Development | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading





   

eMail Scraper
Generate email lists in seconds!


eSource Development presents the ultimate tool for email lead generation! They have decided to release the hottest email list generation tool that allows you to get hundreds (even THOUSANDS) of specific email addresses for any genre, niche, or geographical area.

Internet marketing companies and professionals have been using this tool for years. Now, it has been re-engineered, updated, and released to the public. This 'insider only' software was a closely guarded industry secret until recently.



Watch the Demo

NEW! Trial version available!

DOWNLOAD FOR FREE



  

Dr. Torgo's PC
System Inventory v2.0


Dr. Torgo's PC System Inventory offers a full range of system query options and powerful reporting tools. This software quickly generates reports on several dozen hives of system information including disks, CPU, memory, motherboard, users, ports, services, software, and MORE.

Read more here!

NEW! Trial version available!
DOWNLOAD FOR FREE


Help us out by visiting our sponsors!

iBuyPower







Recent Comments

Comment RSS

What We're Playing





Who's Watchin' Me?