5 September 2012
Using URL Rewrite in IIS7 to have all Requests Handled by a Script

In my post last year about setting up Mercurial on IIS, I left it as an exercise for the reader to allow it so that could be left out of the URLs. As an example, we want to be able to write http://myserver/myrepo instead of http://myserver/

Enter URL Rewrite!

The easiest way to get URL Rewrite installed on your web server is to use Microsoft's Web Platform Installer. Install and run it on your server, and choose to install URL Rewrite 2.0. (While you're at it, I'd also recommend installing IIS Recommended Configuration too).

Now it's installed, you will get a "URL Rewrite" icon in IIS Manager when you select your website. Open it and choose to add a new, blank rule.

Configuring the rule is easy, and we'll use a RegEx trick known as a negative look-ahead assertion. In the match URL section, enter the pattern: ^(?! In the Rewrite URL box, just enter:{R:1}. Leave all the other options as they are, give your rule a name, and hit apply (top right hand corner).

Creating a rule with URL Rewrite

That's all there is to it. The match is setup to match any URL which doesn't start with, so now, any request that doesn't start with will be rewritten so that is inserted at the start of the path.