IIS rewrite with unusual ~ character in the URL

天涯浪子 提交于 2019-12-11 23:42:13

问题


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>

回答1:


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:



来源:https://stackoverflow.com/questions/56871612/iis-rewrite-with-unusual-character-in-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!