Share via


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.

Comments

  • Anonymous
    June 18, 2008
    Awesome!  So glad to see other alternatives out there - especially ones with source available!  thanks for contributing back to the IIS community.  

  • Anonymous
    August 13, 2009
    I am trying to take an existing .htaccess file and convert it to something IIS can use. the code per se is something like this: //Options +FollowSymLinks //RewriteEngine on //RewriteRule ^ecom-catshow/49ers.html$ http://www.collector-corner.com/San-Francisco-49ers-Gifts-and-NFL-Merchandise [L,R=permanent] //RewriteRule ^(.)-(.)/(.*).html /index.php?app=$1&ns=$2&ref=$3 [L,PT] There are a bunch of these categroies I want to rewrite, so if this software can do this without much hassle, let me know. dpotter.net/Technical/2008/10/rewrite-rules-for-iis has some additional info, but I want to here it from what appears to be the "source" before I proceed. Any info mucho appreciated.

  • Anonymous
    August 14, 2009
    you  can do what you want, I think, but better to use the forums at http://iirf.codeplex.com/Thread/List.aspx .

  • Anonymous
    August 18, 2009
    Thax for your solution/article.

  • Anonymous
    December 05, 2011
    The comment has been removed

  • Anonymous
    March 09, 2012
    Everything in this post looks awesome except it does not tell how rewrite a rule In my case, I am testing on my own local machine sot the website looks localhost/user and when I want to create a user, I need to have something like localhost/user/Create That's what I exactly done on my Mac using XAMPP and really want to do it on a PC running IIS. Any hint/idea? Thank you

  • Anonymous
    March 12, 2012
    It does work an rewrite the UR but the same urlManager in config/main.php does not work the same way works on Mac using XAMPP. Do I need to modify the urlManager in config/main.php to work with on a windows machine with IIS? Thanks