繁体   English   中英

如何在web.config中添加多个URL重写规则

[英]How to add multiple URL rewrite rules in a web.config

如何在web.config中添加多个URL重写规则

我想匹配任何包含“ sales”和“ registrationsuccess”的URL。

尝试以下操作时出现错误:

  <rewrite>
    <rules>
        <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
            <match url="(.*sales*)"/>
           <match url="(.*registrationsuccess*)"/>
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$"/>
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
        </rule>
    </rules>
</rewrite>

这是您添加多个规则的方式:

  <rewrite>
    <rules>
        <rule name="Redirect HTTP to HTTPS (Sales)" stopProcessing="true">
            <match url="(.*sales*)"/>
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$"/>
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
        </rule>
        <rule name="Redirect HTTP to HTTPS (RegistrationSucces)" stopProcessing="true">
            <match url="(.*registrationsuccess*)"/>
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$"/>
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
        </rule>
    </rules>
</rewrite>

但是对于您要尝试执行的操作,可以使用一条规则来执行,如下所示:

<rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="ON" />
        <add input="{PATH_INFO}" pattern="^(.*)/sales/(.*)" />
        <add input="{PATH_INFO}" pattern="^(.*)/registrationsuccess/(.*)" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM