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

前端 未结 1 438
[愿得一人]
[愿得一人] 2021-02-18 23:11

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

I want to match any url that contains \"sales\" and \"registrationsuccess\".

I get errors with when I try

相关标签:
1条回答
  • 2021-02-19 00:00

    This is how you add more than one rule:

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

    But for what you're trying to do, you can do it with one rule, like below:

    <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>
    
    0 讨论(0)
提交回复
热议问题