IIS URL rewrite exception

2019-09-02 20:58发布

I have a this rewrite rule currently in place on IIS:

<rewrite>
            <rules>
                <rule name="rewrite asp">
                  <!--Removes the .asp extension for all pages.-->
                  <match url="(.*)" />
                  <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    <add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).asp" />
                  </conditions>
                  <action type="Rewrite" url="{R:1}.asp" />
                </rule>         
            </rules>
        </rewrite>

This enables this:

site.com/allpages --> site.com/allpages.asp

Now, is it possible to create an exception so that a particular page rewrites to another extension?

site.com/exception --> site.com/exception.php

1条回答
Melony?
2楼-- · 2019-09-02 21:34

Create another rule, which is above the 'asp' rule with match pattern:

<match url="^exception$|(.*/)exception$" />

and action:

<action type="Rewrite" url="/{R:1}exception.php" />
查看更多
登录 后发表回答