Tuesday, September 6, 2011

ISAPI Rewrite 3.0 Lite and IIS 7.5 Problems Bypassed With Microsoft URL Rewrite

I have used both free and purchased licenses of  Helicon Tech's ISAPI Rewrite product for years. The Apache mod_rewrite (httpd / htaccess) syntax took some getting used to, but support staff (especially Anton Yaroslav) are fantastic. The forums are very active and have volumes of answered questions.

Unfortunately, their product's future took a bit of a blow today in my shop when I ran into problems installing ISAPI Rewrite 3.0 Lite (0086) on a 64-bit Windows 2008 R2 Server running IIS 7.5.7600.16385. When I would look at the site using the Helicon ISAPI Manager, it would say:
"No properties available for this node."

I found this thread in the forums:

... which addressed this issue for people running version 0069. Support said that the problem was resolved in version 0070, but I was running version 0086 and it still wasn't working. I downloaded 0070 to see if that might help, and it didn't. The final word from Helicon was to buy their $100 APE product because it works better with IIS 7.5. That news sent me Googling for other solutions.

Microsoft URL Rewrite Filter Module

Imagine my surprise when I discovered that Microsoft had a free URL Rewrite product of their own! (It was a relief, but also sad that it might spell the end of my long-standing relationship with Helicon.)

Using Microsoft URL Rewrite

Available here: http://www.iis.net/downloads/microsoft/url-rewrite

This is my first install of URL Rewrite, so I thought I'd create this post as a way to remember what I did.

Once installed, a new icon called "URL Rewrite" will appear in the IIS section of the IIS Manager


I want to write a rule in the mod_rewrite syntax that I am familiar with, so double click URL Rewrite, and then click "Import Rules" in the right-side menu to open the mod_rewrite rules dialog.
My goal was to force HTTP to HTTPS for all sites on the server, so I used this mod_rewrite code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Pasting that code into the "Rewrite rules:" window produced converted rules instantly.

Right click on the line and choose "Rename" to rename the rule. (You can also do this after creating the rule.)

On first test, the filter did not appear to be working. The same thread that discussed using mod_rewrite code also covered the problem I was having: http://forums.iis.net/t/1149780.aspx

Under SSL Settings, "Require SSL" has to be unchecked. When it is checked, the http request won't make it to the ISAPI filter to be redirected.
After that, it worked like a charm!


Microsoft URL Rewrite Filter Module for IIS 7.x
Apache mod_rewrite home
IIS.net "http redirect" thread:
IIS.net Configuration Reference: ISAPI Filters

Helicon ISAPI Rewrite 3.0 download page (most recent version)
Version 0086 x64
Version 0070 x64