IIS URL rewrite exception

2019-09-02 21:19发布

问题:

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:

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