使用空格&进行URL重写" +" web.config中的符号

时间:2017-07-28 13:08:07

标签: asp.net regex url-rewriting web-config

我想重定向旧网址 " http://staging.TempSite.com/about-us/Institute-+target/%20"

新网址"" http://staging.TempSite.com/about-us/news-events""

<rule name="rule59" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
  <add input="{HTTP_HOST}{REQUEST_URI}" pattern="staging.TempSite.com/about-us/Institute-\+target/\s*" />
</conditions>
<action type="Redirect" url="./about-us/news-events" />

我也尝试过跟随模式。

pattern="staging.TempSite.com/about-us/Institute-\+target/\s*$" 
pattern="staging.TempSite.com/about-us/Institute-\+target/ $"

1 个答案:

答案 0 :(得分:0)

@WiktorStribiżew评论几乎是正确的,但它不会起作用。如果您的网址中有+,则需要在配置中启用allowDoubleEscaping。配置示例:

 <system.webServer>
    <security>
        <requestFiltering allowDoubleEscaping="true"/>
    </security>
    <rewrite>
       <rules>
            <rule name="rule59" stopProcessing="true">
                <match url="^about-us/Institute\-\+target/\s*$" />
                <action type="Redirect" url="/about-us/news-events" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>