One of the best things to happen to IIS 7.0 recently is the release of Url Rewriter, the IIS 7.0 url rewriting equivalent to Apache's mod_rewrite.

To ease the process of migrating Apache apps (notably PHP applications that rely on mod_rewrite rules for SEF / friendly urls), the Url Rewriter IIS Manager snapin includes an import function that can import mod_rewrite rules automatically.

Apparently not everyone knows about this little gem, so if you need to get mod_rewrite rules running on IIS 7.0, you should definitely use this to save yourself the few hours of learning the Url Rewriter configuration.  

But, in the first iteration, there are a couple gotchas to watch out for.  This got me pretty good the first few times I used the import, and I had to hunt around the FRT trace logs before I figured things out.

These should save you a couple hours:

1) The {REQUEST_URI} server variable

You may often end up with this variable in imported rules.

Unfortunately, the current release of Url Rewriter has an issue that causes this variable to expand to "" (empty) when processing requests to static files.  This means your rules for jpeg, html, etc extensions will likely fail to run, causing funky results.

Workaround: Replace the {REQUEST_URI} with {URL}  in web.config (see example below).

2) Case-sensitivity

By default, IIS Manager import generates case-sensitive rules.  There is no option to perform a case-insensitive import, although you can edit each rule manually afterwards.

Most urls on IIS 7.0 are are case-insensitive.  This means that much of the time, requests that use case variations may fail to match any of your imported rules, and cause funky behavior.

Workaround: Edit each rule to make it case-insensitive.  You can do it in IIS Manager or in the web.config directly, i.e.:



    <rule name="Imported Rule 1" stopProcessing="true">

      <match url="^(.*)$" ignoreCase="true" />

      <conditions logicalGrouping="MatchAll">

        <add input="{URL}" negate="true" pattern="^/myapp/stylesheets/" ignoreCase="true" />



      <action type="Rewrite" url="/myapp/index.php?title={R:1}" appendQueryString="true" />





For a list of other known issues, be sure to review: (scroll down to "Known Issues").

This should help you avoid some frustration and get your imported rules working right away.

In the meantime, the Url Rewriter team is aware of these issues and is looking into addressing them.  Thankfully with the out of band delivery model afforded by the IIS 7.0 modular architecture, issues like these can be addressed fairly quickly :)