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.