【问题标题】:Webconfig URL Rewrite to Hide Classic ASP ext but not .aspx or other extWeb 配置 URL 重写以隐藏经典 ASP ext 但不隐藏 .aspx 或其他 ext
【发布时间】:2019-10-29 20:26:49
【问题描述】:

我已经能够隐藏 .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.net iis url-rewriting asp-classic web-config


    【解决方案1】:

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

    尝试删除第一条规则。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 是的,做到了。将 Rewrite 反向引用更改为 {R:0}.asp,因为它更有意义,但我认为这两种方式似乎都有效。非常感谢您的回答
      【解决方案3】:

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

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

      【讨论】:

      • 嗨 Rich-Lang,我想(并且正在工作)隐藏 .asp 扩展名,但是当我尝试访问 .net(aspx 等)文件时,规则也会隐藏这些文件并给出 404错误。
      • @DavidBarclay 不清楚“隐藏”是什么意思。我会再说一遍,RequestFiltering 可能是您应该这样做的方式。经过进一步检查,您的第二条规则,尝试将 $ 添加到匹配 URL 的末尾。正则表达式中的 $ 表示“字符串结尾”。让我知道 .asp 是否仍然被阻止。
      • “隐藏”我的意思是删除,搭便车。我想转换所有网址以删除“.asp”扩展名,但是我不想删除其他页面的扩展名,只删除“.asp”页面。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 2016-08-08
      • 1970-01-01
      相关资源
      最近更新 更多