温馨提示:本文翻译自stackoverflow.com,查看原文请点击:redirect - IIS rewrite with unusual ~ character in the URL
redirect iis url-rewriting iis-8 iis-8.5

redirect - IIS用URL中的异常〜字符重写

发布于 2020-03-27 10:43:48

我的网址格式如下:

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

我想重定向到:

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

我已经尝试了几个变体,但无法将其拾起(尽管在IIS URL重写正则表达式测试器中进行了测试)。

<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>

查看更多

查看更多

提问者
Seany84
被浏览
52
Brando Zhang 2019-07-04 09:51

根据您的描述,我建议您可以尝试使用以下url重写规则。

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

结果:

在此处输入图片说明