-->

从https重写URL://到http://在IIS7(Rewriting URLs from ht

2019-07-21 10:11发布

我试图从形式重写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://的请求都平了无形的重写引擎。

规则做工精细; 见下面的回答。

Answer 1:

事实证明, 我有口:443绑定到不同的网站!

上述重写规则做工精细对于http://到https://改写,反之亦然 - 尽管有可能是更理想的或简单的方法可以做到这一点。

离开这里这个问题,为今后的航海找到,因为我没有看到HTTPS的许多很好的例子://为http://在网络上重写方案。



Answer 2:

这篇文章是有点老了,但我想回答。 我使用ASP.Net MVC3,和法比奥的回答上面并没有为我工作。 最简单的解决方案,我想出了处理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>


Answer 3:

您的解决方案的工作,但问题是:你的第二个指令杀死任何链接第一个指令是不计费/,包括你的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>


Answer 4:

请首先考虑结合 HTTPS到您的网站下面进行重定向模块来工作是必不可少的(所以绑定自签名有效凭证的Web应用程序)

在web.config中最后一部分重定向HTTPShttp:

 <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中重写模块见下图

来源:看科技网的一步引导更多的细节和步骤。



文章来源: Rewriting URLs from https:// to http:// in IIS7