从http到https永久重定向规则排除特定网址

问题描述 投票:0回答:2

我在下面有以下重定向规则强制所有http流量到https。但是,我们需要提供一些在https中显示问题的页面,我们需要强制它们为http,直到我们可以将它们更新为在https下工作。

  <rule name="Redirect to https" stopProcessing="true">
    <match url=".*" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>

    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
  </rule>

所有这些页面都有一个共同点,即“/ SSLA /”是网址的一部分。我不是我想成为的重写大师,但我有几种可能的想法来解决这个问题:

a)以某种方式更新此规则以使用“/ SSLA /”排除网址。

B)在此规则之前添加规则以捕获任何带有“/ SSLA /”的规则,如果它转到https并重定向到http并且(在相同的规则或单独的规则中?)也对http请求没有做任何事情但是停止处理所以它不会将此全局http命中为https重定向规则。

问题是,我对正则表达式或重写规则都不是很好,所以我不太确定如何完成这些解决方案中的任何一个(实际上甚至不确定哪个是“正确”处理这个问题的方法)。

所以...请帮忙! :)

编辑:我应该注意,我已经更新了c#代码以重定向到这些页面的http,但当然这会导致循环使用上述规则。但我只是指出这一点,我所需要的只是重定向规则,不强制对具有“/ SSLA”的页面的http请求为https,因为代码会将任何此类https请求重定向到http。但是,如果让重定向规则强制https请求中包含“/ SSLA /”到http也是一件小事,那么我可以删除执行相同操作的c#代码。

url-rewrite-module
2个回答
1
投票

试试用

<match url="((?!SSLA).)*" />

insteed

<match url=".*" />

1
投票

您应该使用两个重写规则:

  1. 用于重定向HTTPS - > HTTP用于SSLA/*页面
  2. 用于重定向HTTP - > HTTPS用于非SSLA/*页面。

请查看下面的示例我如何过滤SSLAnon SSLA页面

    <rule name="Redirect to http SSLA" stopProcessing="true">
       <match url="^SSLA" />
       <conditions>
           <add input="{HTTPS}" pattern="on" ignoreCase="true" />
       </conditions>
       <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>

    <rule name="Redirect to https" stopProcessing="true">
       <match url="^SSLA" nagate="true" />
       <conditions>
           <add input="{HTTPS}" pattern="off" ignoreCase="true" />
       </conditions>
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
© www.soinside.com 2019 - 2024. All rights reserved.