Rewriting URLs on IIS5, IIS6, or IIS7 (mod_rewrite on IIS?)

A couple weeks ago, Bill Staples made a splash when he announced a Rewrite Module for IIS7: https://blogs.iis.net/bills/archive/2008/05/31/urlrewrite-module-for-iis7.aspx 

But you can get mod_rewrite -like capability, even on IIS6, using the free IIRF download.

Rewriting URLs?  This is the magic in your web server that allows your user to type something neat and clean, like https://server/products/WidgetX , but yet on the server side it is served by a page that would normally be available like so: https://server/ProductQuery.aspx?productName=WidgetX .

URL Rewriting has lots of benefits, one of which is search-engine optimization.  the URL Rewriting module for IIS7 is therefore is very interesting for lots of people. Definitely check it out if you are using Windows Server 2008, or Windows Vista (either of which is a pre-req or IIS7).  Some of you are not yet in that boat.  You're still running Windows Server 2003, or you are running a public IIS website on Windows XP (Shocking, maybe, but very common).  You're not on IIS7, yet you still want URL rewriting.  You want it all, don't you?

You've seen the guidance on how to do this with a .NET HttpModule, but you don't want to run every URL through ASP.NET.  Maybe you don't even have ASP.NET installed on the machine?  Maybe you are running a website with Ruby, or PHP.  Maybe it is a Joomla thing, or ColdFusion.  Whatever, you're running Windows and IIS6 or IIS5, and you want URL rewriting.  The .NET approach isn't the right thing, and the IIS7 module is a non-starter.  What other choices have you got?

As BillS points out in his blog post, there are commercial providers of IIS Filters. They have fine products, good documentation, good support staffs and policies.   There are other options. 

A long while ago I posted about a URL rewriting ISAPI  Filter.  I put it together as a sort of proof that it could be done, but then people wanted to really use it.  So I called it IIRF, promoted it to a codeplex project, and of course in keeping with the codeplex philosophy, it is open source.  I've been maintaining IIRF on the side ever since then, adding features, fixing bugs and providing guidance on how to use it in the forums on the codeplex project site.

I wanted to provide an update here.  There's now a v1.2.14 release of IIRF, available on codeplex. It is the latest stable release. (you can always click to Latest Stable release) This one works on IIS5 or 6 or 7.  There's no installer nor is there a graphical rules designer. But it works nicely, and performs well.   It does rewrites and redirects, based on a regular-expression powered pattern-matching capability (provded by PCRE).  The config resides in a text file with a syntax much lilke but not exactly the same as the ini file for mod_rewrite on Apache HTTPD, and it is automatically reloaded each time you modify it.  It has the -f and -d features from Apache's mod_rewrite, features that are not present on some commercial filters.  The IIRF documentation isn't fancy, but the readme is clear and complete.  There's a tool for testing out the RewriteRules.  IIRF has a log feature that lets you see what the filter is doing, if you like.

There's also a 1.2.15 release, currently in preview. This one adds a RewriteHeader feature, which is nice.  It lets you set any arbitrary HTTP Header in the request, based on the same kinds of conditions and pattern matching that you use to rewrite URLs.

One of the biggest feature requests I got was to allow the filter to be installed once, but have many distinct configuration settings, for different websites, different web applications in IIS.  What it means is you install the filter once, and then you can have 50 or 100 (or more) different ini files, each with its own rewriting rules.  Great for hosters or consolidated servers where many apps are running on a single instance of IIS.  This new feature is available in the v2.0 release, also currently in preview. (The feature required a redesign of the way the configuration was slurped in, and I felt this was significant enough to warrant a new major version number.) 

Definitely check out IIRF if you want a cheap Rewriting filter for IIS, with a good feature set.