Thursday, June 24, 2010

A Little URL Rewriting with Managed Fusion Rewriter

I'm stuck on IIS 6 for now and I needed to do a bunch of URL rewriting. No one wants to spend money these days, so we didn't spring for the Helicon ISAPI_Rewrite product. I have a lot of legacy URLs to handle, but we won't keep them in place for more than a year and by that time we'll likely be on IIS 7 with its own rewriting tools.

I went with the Managed Fusion Rewriter tool both for its promised flexibility and the fact that it used the Apache mod_rewrite syntax.

I like it, but I ran into a few quirks I thought I'd pass along.

First, if you're using RewriteCond and trying to grab query string parameter values, %1 will hold the name/value pair. %2 will hold the value you're probably looking for. If you have multiple values you're catching you would just continue to increment -- %3, %4, etc. Here's an example that works as I expected it:

RewriteCond %{QUERY_STRING} ^lessonid=([0-9]+)$
RewriteRule ^/Explore/KeyQuestions.aspx$ /Analyze/Display/%2 [R=301,NC,L]


Second, in mod_rewrite you can apparently stack multiple RewriteCond one on top of another. I was not able to get it to work with this tool.

No comments: