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