Adventures of a wannabe geek!

Ranting within

IIS Rewrite Tool – the Pain of a Simple Rule Change

I had a real pain point with the IIS Rewrite tool today. I wanted to take an out of the box canonical rewrite rule and then modify it slightly to fit my own scenario. This tool is very easy to setup simple, out of the box rules – e.g. in order to get a simple canonical url rewrite ( to redirect to then we would do as follows:


You then enter the primary host name – in my case it is www.test.comimage

That is it! The rule is now set up – pretty easy eh! This will redirect any request that isn’t to become The following code is added to the web.config file in order to make this work:

So this wasn’t quite right for my setup. I have a main URL that sits with the load balancer – lets say that is but I have individual URLs associated with the individual servers lets say an example is I use individual server URLs for server monitoring – Pingdom will constantly hit a specific page on the individual server to test for uptime. The canonical rule I have listed above will redirect the individual URL to the load balanced URL so I had to try and change the built in rule. Firstly I tried to do this via the web.config and adding my own lines. This did not work at all. I could find little documentation about how the rule is constructed so I was basically just “hacking” the rule to try to get it to work.

Then I went and used the built-in editor for the IIS rewrite tool. When I seen the list of rules I double clicked on the rule and got the following screen:


This is where I finally got my editing correct. I had to add a condition to list -


This did not offer my any type of drop down list for the different options I had for condition input – as you can see it is currently selected as {QUERY_STRING}. I didn’t realise I had to change this. But once I had figured this out I changed it to look as follows:


This was the correct rule – it says in pseudo terms – if the URL does not match this format then perform the redirect to the canonical host. This left me with the following web.config entry


This was way too easy to mess up. I would love there to be a way to test my rules in an actual scenario – a sample application that I could pass requests to and see what the response would be. I hope you don’t fall into this rewrite rule trap! Please, IIS team, make it easier to test the rules that I have created.