首页 > 解决方案 > IIS URL 重写规则排除多个文件

问题描述

我有一个强制 HTTPS 的 IIS URL 重写规则,除非该页面是 healthcheck.html(超过端口 80)。当我使用匹配 URL 逻辑时,这就像一个魅力,如下所示:

<match url="healthcheck.html" negate="true" />

但是,我不仅需要排除此页面,还需要排除名为 Dir1 的目录中名为 OtherCheck.aspx 的第二个文件

我没有发现其他人排除了两个文件的任何实例,尤其是一个不在根目录中的文件。是否可以有两个文件名排除项?我试过了,但没有奏效:

<match url="healthcheck.html&/Dir1/OtherCheck.aspx" negate="true" />

标签: iisurl-rewrite-module

解决方案


文件和文件夹结构:s1(根文件夹):

健康检查.html(文件)

s2(子文件夹):

page1.html(文件)

您可以使用以下 url 重写规则来排除多个文件:

 <rule name="Redirect to HTTPS multiple file" enabled="true" stopProcessing="true">
     <match url="(.*)" />
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" />
                    <add input="{REQUEST_URI}" pattern="^/healthcheck.html" negate="true" />
                    <add input="{REQUEST_URI}" pattern="^/s2/page1.html" negate="true" />
     </conditions>
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
   </rule>

https重定向:

在此处输入图像描述

排除文件: 在此处输入图像描述 在此处输入图像描述

注意:您可以根据需要设置文件和文件夹名称。

问候, 雅尔帕


推荐阅读