【问题标题】:Redirect HTTPS to HTTP for specifc page and its underlaying rsources针对特定页面及其底层资源将 HTTPS 重定向到 HTTP
【发布时间】:2019-01-24 08:41:50
【问题描述】:

我有要求将任何 http 请求重定向到 https,即 http://test.amey.com/sitenamehttps://test.amey.com/sitename 为了实现这一点,我在 IIS url rewrite 中应用以下规则

<rule name="HTTP to HTTPS Redirect" patternSyntax="Wildcard" stopProcessing="true">
   <match url="*" />
   <conditions logicalGrouping="MatchAll">
      <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/sitename" />
</rule>

上述规则工作正常,它将任何 http 请求重定向到 https。

但我有另一个要求,我想将某些页面的 https 请求重定向到 http 以及它下面的任何内容,即 https://test.amey.com/sitename/reports/index - (其中报告是控制器名称和索引是操作方法) 到 > http://test.amey.com/sitename/reports/index

报告在此目录下有更多页面,所以我想应用规则,报告下的任何内容都应重定向到 http,即

https://test.amey.com/sitename/reports/saleshttp://test.amey.com/sitename/reports/sales

https://test.amey.com/sitename/reports/weeklysalehttp://test.amey.com/sitename/reports/weeklysale

我一直在寻找解决方案,但无法解决任何问题。任何帮助都将是很大的优势。

谢谢

【问题讨论】:

    标签: http redirect iis https url-rewriting


    【解决方案1】:

    以下解决方案始终将用户重定向到 Https,但条件中定义的某些页面除外。

    <rule name="Redirect to HTTPS">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTPS}" pattern="OFF"/>
                    <add input="{URL}" pattern="(.*)reports" negate="true" />
                  </conditions>
                  <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
         </rule>
    
         <rule name="Redirect to HTTP">
                  <match url="(.*)" />
                  <conditions>
                    <add input="{HTTPS}" pattern="ON"/>
                    <!-- condition below will satisfy that any URL request containing Reports will redirect to http  --> 
                    <add input="{URL}" pattern="(.*)reports" />
                  </conditions>
                  <action type="Redirect" url="http://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
         </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 2013-10-23
      • 2012-10-08
      • 2012-11-07
      • 2013-10-18
      • 1970-01-01
      相关资源
      最近更新 更多