Skip to main content

URL Rewriting

Recently it came to my attention that google and other major search engines were no longer indexing querystrings. I'm not sure when the switch took place but on a number of sites I maintain the majority of the content is no longer indexed.

Enter URL Rewriting which allows us to convert:
http://foo.com/tools/product/mcleod

Into
http://foo.com/tools.aspx?product=mcleod

This is extremely commonplace in the Apache world, but how do we accomplish it within IIS?

Today I downloaded Helicon's ISAPI_Rewrite 2.11 Lite. It's free and best of all it works off regular expressions.

Installation and Configuration
1.) Download ISAPI_Rewrite
2.) Install
3.) Open the global httpd.ini file
Start > Programs > Helicon > ISAPI_Rewrite > httpd.ini
4.) Add a rule to process querystrings, in this example we'll loop through the querystring of all files ending in .aspx
[ISAPI_Rewrite]

# Repath .aspx files
RewriteRule (.*?\.aspx)(\?[^/]*)?/([^/]*)/([^/]*)(.*) $1(?2$2&:\?)$3=$4$5 [NS,I]


This will turn:
http://foo.com/tools/product/mcleod

Into:
http://foo.com/tools.aspx?product=mcleod

Extra points if you've actually used a McLeod (or at least know what one is).

The Lite version of ISAPI_Rewrite only works at the global level, and cannot be configured to work differently in each virtual directory. So far it is working really well, and I may be buying a full version in the near future.

Link

Comments