【问题标题】:Rewriting URLs from https:// to http:// in IIS7在 IIS7 中将 URL 从 https:// 重写为 http://
【发布时间】:2010-12-04 21:37:00
【问题描述】:

我正在尝试从表单中重写 url:

https://example.com/about

表格

http://example.com/about

使用IIS7 URL rewriting

<!-- http:// to https:// rule -->
<rule name="ForceHttpsBilling" stopProcessing="true">
  <match url="(.*)billing/(.*)" ignoreCase="true" />
  <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="false" />
  </conditions>
  <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>

<!-- https:// to http:// rule -->    
<rule name="ForceNonHttps" stopProcessing="true">
  <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
  <conditions>
      <add input="{SERVER_PORT}" pattern="^443$" />
  </conditions>
  <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>

我很茫然;我一直在网上浏览示例并尝试我能想到的每一种语法。对于任何 https 请求,我指定的重写规则似乎根本 不起作用,就好像所有 https:// 请求对重写引擎完全不可见。

规则工作正常;请参阅下面的答案。

【问题讨论】:

  • 对我来说闻起来像一个基本的安全“功能”
  • 这对我来说就像一个服务器故障问题......
  • @Charlie,没有。这是编码和管理的问题之一,所以把它留在它开始的网站上(就像很多脚本问题一样)
  • 这确实是一个很好的配置 http 到 https 的示例,反之亦然。我只是在寻找这样的东西。尝试了其他几个,但他们遇到了一个或其他问题。
  • 解决这个问题 - 没有有效的证书就无法完成,对吗?即,由于我没有安装证书,我无法强制 https 请求转到 http...

标签: iis-7 https url-rewriting url-rewrite-module


【解决方案1】:

原来我将端口 :443 绑定到了不同的网站!

上述重写规则适用于 http:// 到 https:// 重写,反之亦然 - 尽管可能有更优化或更简单的方法来做到这一点。

把这个问题留在这里供以后的航海者寻找,因为我没有在网上看到很多关于 https:// 到 http:// 重写场景的好例子。

【讨论】:

  • 我发现使用上述 https 到 http 规则导致我的 https 页面上的所有 css、javascript 和图像资源都被作为 http 获取。我删除了这条规则并添加了一个出站规则,将我的安全页面上的 a href 标记重写为 http://{HTTP_HOST}/{R:0} 以强制从 https 切换到 http。不会使用 https 意外手动导航到非安全页面,但这对我来说没问题
  • Pat James,我也遇到了这个问题。您介意分享您的出站规则吗?
  • 谢谢你是一个救生员。 :))
【解决方案2】:

这个帖子有点老了,但我想回答一下。我正在使用 ASP.Net MVC3,上面 Fabio 的回答对我不起作用。我想出的处理 https 重定向到 http 的最简单解决方案,同时仍然允许有效的 https 页面请求安全内容,只是在我的 https/http 重定向上方添加白名单规则:

    <rule name="WhiteList - content folder" stopProcessing="true">
      <match url="^content/"/>
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
      <action type="None"/>
    </rule>
    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)billing/(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/billing/" redirectType="SeeOther" />
    </rule>
    <rule name="ForceNonHttps" stopProcessing="true">
      <match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
      <conditions>
        <add input="{SERVER_PORT}" pattern="^443$" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
    </rule>

【讨论】:

    【解决方案3】:

    请首先考虑 绑定 https 到您的网站,以使以下重定向模块正常工作是必不可少的(因此使用 self-signedvalid 绑定您的网络应用 证书)

    web.config 中将 https 重定向到 http 的最后一部分:

     <rewrite>
        <rules>
            <rule name="Force NonHTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                   <add input="{HTTPS}" pattern="on" />
                </conditions>
                <action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
            </rule>
        </rules>
    </rewrite>
    

    如果您在重写模块中需要等效的 IIS GUI,请参见下图

    来源:查看tech-net 了解更多详细信息和分步指南。

    【讨论】:

      【解决方案4】:

      您的解决方案有效,但问题是:您的第二条指令杀死任何链接的第一条指令不是 (.)billing/(.),包括您的 css、js 和图像。

      您可以使用此 https 到 http 规则:

      <rule name="HTTPS to HTTP redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
      <add input="{RequiresSSL:{R:1}}" pattern="(.+)" negate="true" />
      <add input="{HTTPS}" pattern="on" ignoreCase="true" />
      <add input="{REQUEST_URI}" pattern="^(.+)\.(?!aspx)" negate="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}/{R:1}" />
      </rule>
      

      【讨论】:

        猜你喜欢
        • 2011-09-15
        • 2015-02-11
        • 2014-09-20
        • 2014-07-18
        • 2011-06-02
        • 1970-01-01
        • 2021-12-28
        • 1970-01-01
        • 2012-07-23
        相关资源
        最近更新 更多