我在我的Web.config中设置了这些规则:
<rules>
<rule name="replacedash">
<match url="(.*)(-)(.*)\.aspx$" />
<action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
</rule>
<rule name="extensionless" stopProcessing="true">
<match url="(.*)\.aspx$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
我已将我的网站从普通的ASP.NET升级到ASP.NET MVC,我已经编写了这些规则,以防万一在搜索引擎中仍有一些旧的缓存链接,扩展名为.aspx;但是,我的Web服务器上有一些目录仍然包含.aspx文件,原因很充分,我的规则也在重写这些扩展。
如何从继承我的规则中排除这些文件夹?
基于以下解决方案:
How to exclude a directory with IIS URL rewriting?
你可以这样做:
<rules>
<rule name="ignore web forms folder 1" stopProcessing="true">
<match url="^webformsfolder1/" />
<action type="None" />
</rule>
<rule name="ignore web forms folder 2" stopProcessing="true">
<match url="^webformsfolder2/" />
<action type="None" />
</rule>
<rule name="ignore web forms folder 3" stopProcessing="true">
<match url="^webformsfolder3/" />
<action type="None" />
</rule>
<rule name="replacedash">
<match url="(.*)(-)(.*)\.aspx$" />
<action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
</rule>
<rule name="extensionless" stopProcessing="true">
<match url="(.*)\.aspx$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>