Warm tip: This article is reproduced from stackoverflow.com, please click
redirect iis url-rewriting iis-8 iis-8.5

IIS rewrite with unusual ~ character in the URL

发布于 2020-03-27 10:19:12

I have a URL in the format:

https://www.example.com/aaa/bbb/product/~productId=abc123

Which I would like to redirect to:

https://www.example.com/product/abc123

I have tried a couple of variations on this and just cannot get this to pick it up (despite testing this in the IIS URL rewrite regex tester).

<rule name="Custom rule 12" stopProcessing="true">
    <match url="aaa/bbb/product/(.*)" />
    <conditions>
        <add input="{HTTP_URL}" pattern="~productId=(.*)$" />
    </conditions>
    <action type="Redirect" url="/product/{C:1}" appendQueryString="false" />
</rule>
Questioner
Seany84
Viewed
50
Brando Zhang 2019-07-04 09:51

According to your description, I suggest you could try to use below url rewrite rule.

            <rule name="specialcharacter" stopProcessing="true">
                <match url="aaa/bbb/product/~productId=(.*)" />
                <action type="Redirect" url="https://www.example.com/product/{R:1}" />
            </rule>

Result:

enter image description here