39

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

https://example.com/about

到表格

http://example.com/about

使用IIS7 URL 重写

<!-- 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://对重写引擎都是完全不可见的。

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

4

4 回答 4

28

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

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

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

于 2009-10-08T08:11:06.203 回答
8

这个帖子有点老了,但我想回答一下。我正在使用 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>
于 2012-09-26T18:01:11.013 回答
7

请首先考虑将 https绑定到您的网站以使以下重定向模块正常工作是必不可少的(因此使用自签名有效证书绑定您的 Web 应用程序)

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了解更多详细信息和分步指南。

于 2017-04-26T10:32:26.573 回答
3

您的解决方案有效,但问题是:您的第二条指令杀死任何链接的第一条指令不是 (. )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-08-04T19:00:40.987 回答