Webconfig URL 重写以隐藏经典 ASP ext 但不是 .aspx 或其他 ext

Webconfig URL Rewrite to Hide Classic ASP ext but not .aspx or other ext

我已经能够隐藏 .asp 扩展名,但它也删除了任何其他扩展名并指向 .asp 我知道这只是一个配置问题,但没有 webconfig 文件配置的经验,想知道是否有人有快速解决方案来节省我几个小时! 下面是我从部分 webconfig 文件中得到的代码

<rewrite>
  <rules>
    <rule name="Hide .asp Ext">
      <match url="^(.*)$" ignoreCase="true" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_FILENAME}.asp" matchType="IsFile" />
        </conditions>
        <action type="Rewrite" url="{R:0}.asp" logRewrittenUrl="true" />
      </rule>
      <rule name="Redirect .asp Ext" stopProcessing="true">
         <match url="^(.*).asp" ignoreCase="true" />
           <conditions logicalGrouping="MatchAny">
            <add input="{URL}" pattern="(.*).asp" />
           </conditions>
           <action type="Redirect" url="{R:1}" />
       </rule>
  </rules>
</rewrite>

在我看来,第一条规则首先将所有内容转换为 .asp 扩展名?

尝试删除第一条规则。

您定义了两个规则。看起来所有请求的第一个匹配项和 "rewrites" 它们具有 .asp 扩展名。第二个在 .asp 上匹配,然后执行某种重定向。

从您的问题中不清楚的是您希望如何 'hide' 这些文件。如果你想拒绝对 .asp 的所有请求,你最好添加一个请求过滤 "File Extensions" https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/index

试试这个?似乎在我的测试服务器上工作。

        <rule name ="redirect .asp to none" stopProcessing="true">
            <match url="(.*)\.asp$" />
            <action type="Redirect" url="{R:1}" redirectType="Permanent" />
        </rule>                  
        <rule name="hide .asp extension" stopProcessing="false">
          <match url="(.*)" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:1}.asp" />
        </rule>