Webconfig URL 重写以隐藏经典 ASP 分机,但不隐藏.aspx或其他分机



我已经能够隐藏.asp扩展名,但它也删除了任何其他扩展名并指向.asp我知道这只是一个配置问题,但没有 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扩展?

尝试删除第一条规则。

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

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

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

从您的问题中不清楚的是您希望如何"隐藏"这些文件。 如果您想拒绝所有.asp请求,最好添加请求过滤"文件扩展名"https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/index

最新更新