How To: Create Custom ASP URLs with Querystrings using ISAPI Rewrite


ISAPI Rewrite is a powerful URL manipulation engine based on regular expressions. It acts mostly like Apache’s mod_Rewrite, but is designed specifically for Microsoft’s Internet Information Server (IIS). ISAPI_Rewrite is an ISAPI filter written in pure C/C++ so it is extremely fast. ISAPI_Rewrite gives you the freedom to go beyond the standard URL schemes and develop your own scheme.

Below are a few very easy to follow ISAPI Rewrite rules using regular expressions:



EXAMPLE 1

DESCRIPTION:
use one querystring as a subdirectory

ORIGINAL URL:
domain.com/member.asp?username=brad

NEW URL:
domain.com/brad

ISAPI REWRITE RULE:
RewriteRule /([^/]+) /member.asp\?username=$1 [I,L]



EXAMPLE 2

DESCRIPTION:
use two querystrings as subdirectories

ORIGINAL URL:
domain.com/member.asp?username=brad&page=2

NEW URL:
domain.com/brad/2

ISAPI REWRITE RULE:
RewriteRule /(?!images|js|css)([^/]+)/([^/]+) /member.asp\?username=$1&page=$2 [I,L]

* notice the (?!images|js|css) section of the rule. This piece tells the above rule to ignore those subdirectories (images, js, css).



EXAMPLE 3

DESCRIPTION:
use one hard coded subdirectory and one querystring as a subdirectory

ORIGINAL URL:
domain.com/member.asp?user_id=1

NEW URL:
domain.com/widget/1

ISAPI REWRITE RULE
RewriteRule /widget/([^/]+) /member.asp\?user_id=$1 [I,L]


Search engine spiders, and users, will ONLY see the newly formatted link. The querystrings are still being passed to the server, but they are not visible to anyone surfing the site. This is a HUGE advantage for making a dynamic site SEO friendly. Search engine spiders have always had issues with long complex querystrings, but masking the URL using ISAPI REWRITE has finally closed the gap between dynamic sites and SEO.

ISAPI Rewrite Homepage

Related posts:

  1. How to: 301 Redirect from one domain to another using mod_rewrite
  2. How To: Create Facebook Like Username URLs in WordPress
  3. How To: Create ASP and AJAX username availability check example
  4. How to: Update Pownce using ASP
  5. How To: Update your Twitter status with ASP
Enjoy this post? Be sure to subscribe to my RSS feed and my WordPress Tips and Tricks Newsletter! Also check out my new book: Professional WordPress

Speak Your Mind

*