How to URL Rewrite in IIS to URL encode incoming requests that have unencoded characters?

30 views Asked by At

Basically, is it possible to use URL Rewrite to encode a set of unencoded characters in a complex long query string, but not some of the special characters such as the & in the query string?

The set of parameters might be arbitrarily long.

I've got something like this, but I think the condition and negate just means it's not going to process any of it if there's an ampersand, when what I want is for it to not URL Encode the ampersand.

<rules>
        <rule name="EncodeBraces" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="&amp;" ignoreCase="true" negate="true" />
        </conditions>
        <action type="Rewrite" url="{UrlEncode:{R:0}}" />
    </rule>
</rules>

What I want is for something like this:

/something/action?id=123&other=567&properties=[{prop1=a, prop2=b}]

to have the [{}] encoded. And maybe ,?...with an unknown amount of sets of [{}]

Any help would be amazing. Not sure URL Rewrite can do this!

I've included the example of using an app.config and URL Rewrite to do what I want, but it's not working as expected.

0

There are 0 answers