ASP.NET-将所有https请求重写为http

ASP.NET-将所有https请求重写为http,asp.net,http,iis,https,url-rewrite-module,Asp.net,Http,Iis,Https,Url Rewrite Module,我的问题正是其中一个,我决定尝试将所有https请求重写为http。我已经搜索了很长时间,但似乎没有一个明确的方法来实现这一点-看到这些问题(没有解决方案): 我已将重写模块添加到IIS,并在web.config中尝试了以下操作: <rewrite> <rules> <clear /> <rule name="force http" stopProcessing="true"> <match url="(.*)

我的问题正是其中一个,我决定尝试将所有https请求重写为http。我已经搜索了很长时间,但似乎没有一个明确的方法来实现这一点-看到这些问题(没有解决方案):

我已将重写模块添加到IIS,并在web.config中尝试了以下操作:

<rewrite>
  <rules>
    <clear />
    <rule name="force http" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

没有运气。url重写模块肯定已成功安装在IIS上

edit2:尝试了以下操作但未成功:

<system.webServer>
<rewrite>
  <rules>
    <clear />
    <rule name="force http" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="on" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^(?:www)?\.test.site\.com$"
            negate="true" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}"
            redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
</system.webServer>


我重新启动了IIS,重写规则反映在inetmgr中。加载<代码>https://test.site.com/
仍然使用https加载。

有几件事。首先,当HTTPS打开而不是关闭时,需要进行重写。其次,对于需要通过HTTPS运行的应用程序,您需要将其从重写中排除。修改后的重写规则应如下所示:

<rewrite>
  <rules>
    <clear />
    <rule name="force http" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="on" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^example\.com$" 
            negate="true" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" 
            redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

这将保持
https://example.com/login
在https和所有其他URL上将被重定向到http。例如,
https://test.example.com/login
将被重定向到
http://test.example.com/login
。此重写规则需要放置在具有HTTPS绑定的站点上,以便重写正常工作


请注意,当使用301永久重定向时,某些浏览器不会在后续点击时向服务器发出请求,因此更改规则后需要清除浏览器缓存。“网络”选项卡甚至可能撒谎,说请求已发出,但像Fiddler或Wireshark这样的外部工具会让您确定。

您是否可以选择向服务器添加额外的IP地址,以便更改绑定?有这个选项,但我想让URL重写按照预期的方式工作似乎URL重写模块设计为仅在将请求分配给IIS站点后处理,因为匹配URL在主机之后启动。我认为IP地址是最好的,但它可以在没有它的情况下完成。请看下面的答案。非常感谢beavel!这些站点位于同一域:
https://www.site.com/
http://test.site.com/
-这会有问题吗?如果有什么需要改变的话,你可以更新你的答案吗。我将很快进行测试。这不应该是一个问题,因为它将匹配所有不是www.site.com的内容。如果您的用户希望以site.com的身份访问www.site.com,那么模式需要如下:^(?:www)?\.site\.com$这将使www成为可选的。我更新了我的问题。模式是否考虑了
.com
之后的路径<代码>https://test.site.com/login@user982119我已经更新了我的答案,以反映新的模式和示例。请参阅我关于测试的警告。已清除缓存。它不会重定向。