Iis – How to identify which rewrite rule is being trigger on IIS 7.5

iisiis-7.5rewrite

I have a set of rewrite rules (offhand, I would say around 40-50) for a given server. It's basically to handle and reroute mangled URLs so that bad links still go to where they're supposed to go.

I've come across an URL that is redirecting and I can't figure out which rewrite rule it is applying.

My background is Apache and in that case I'd simply enable a rewrite log and look at the logged output to figure out what was happening. Is there an equivalent way to do this in IIS?

bonus round

Any way for me to view & edit the rewrite rules in a text file rather than the GUI interface?

Best Answer

Main Answer:

You can use the "Failed Request Tracing" feature to trace all kinds of requests in IIS 7.x (even rewritten ones). Here's a lovely article from learn.iis.net on just that.

Bonus round weigh-in:

Depending on the scope of the rewrite rules (configuration-wise), the rules are stored in either:

  • applicationHost.config - section: configuration/system.webServer/rewrite/globalRules
  • web.config - section: configuration/system.webServer/rewrite/rules

All IIS config files are basically XML files, so fire up your favorite XML editor and edit away. Beware that IIS 7.x (specifically the WAS service that picks up and validates configuration changes on-the-fly) is very sensitive to malformed XML, or configuration files that don't adhere to the IIS Schema, so be sure to back up the files before you edit them.

See the IIS.NET configuration reference for examples of built-in sections and properties, or head over to MSDN and check out the documentation

Related Topic