IIS URL Rewrite not working with query string

As described in Microsoft’s documentation:

It is important to understand how certain parts of the URL string can
be accessed from a rewrite rule.

For an HTTP URL in this form:
http(s)://{host}:{port}/{path}?{querystring}

The {path} is matched against the pattern of the rule. The
{querystring} is available in the server variable called QUERY_STRING
and can be accessed by using a condition within a rule.

Rule conditions allow defining additional logic for rule evaluation…
Rule conditions are evaluated after the rule pattern match is successful.

In the URL you wanted to rewrite as a redirect, your {host} = "www.site.com", {path} = "" and {querystring} = "q=node/17". So the {path} part in the URL you wanted to redirect is actually empty, and the rule you used in your question was matched against it and did not match.

Your solution is indeed valid, so I’ll quote it here:

<rule name="Node17" stopProcessing="true">
    <match url=".*" />
<conditions>
    <add input="{QUERY_STRING}" pattern="q=node/17" />
</conditions>
<action type="Redirect" url="http://www.example.com" appendQueryString="False" />
</rule>

Leave a Comment