Redirect HTTP到HTTPS重定向-IIS 8.5工作不正常

Redirect HTTP到HTTPS重定向-IIS 8.5工作不正常,redirect,iis,iis-8.5,Redirect,Iis,Iis 8.5,我在这里以及网上(IIS博客等)读了很多帖子。我试图强制所有从domain.com到www.domain.com的连接,同时强制从HTTP到HTTPS的请求 <!-- Redirect to HTTPS --> <rewrite> <rules> <rule name="http to https" stopProcessing="true">

我在这里以及网上(IIS博客等)读了很多帖子。我试图强制所有从domain.com到www.domain.com的连接,同时强制从HTTP到HTTPS的请求

<!-- Redirect to HTTPS -->
        <rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
我正在使用这组规则并进行重写,但唯一发生的事情是它可以重定向,但不能重定向到SSL

<!-- Redirect to HTTPS -->
<rewrite>
    <rules>
        <rule name="Redirect to www" stopProcessing="true">
            <match url="(.*)" />
            <conditions trackAllCaptures="false">
                <add input="{HTTP_HOST}" matchType="Pattern" pattern="^mydomain.com$" ignoreCase="true" negate="false" />
            </conditions>
            <action type="Redirect" url="{MapProtocol:{HTTPS}}://www.mydomain.com/{R:1}" />
        </rule>
    </rules>
    <rewriteMaps>
        <rewriteMap name="MapProtocol" defaultValue="http">
          <add key="on" value="https" />
          <add key="off" value="http" />
        </rewriteMap>
    </rewriteMaps>
</rewrite>


这篇文章-

编辑:所以我找到了这篇博客文章:并尝试一下,瞧!工作得很有魅力。我不知道为什么上面发布的规则会起作用,但在我的情况下,下面的规则会起作用并成功地获取所有非www流量,并将其重定向到wwwhttps

<!-- Redirect to HTTPS -->
        <rewrite>
            <rules>
                <rule name="http to https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>

在使用URL重写模块从http重定向到https时,我们也遇到了同样的问题,但在关闭IIS中的require ssl模块后,问题就解决了

  • 转到网站的SSL设置
  • 取消选中需要SSL复选框
  • 应用设置并重新启动iis

  • 在某些情况下,这是一个很难实现的目标,但我删除了网站的端口80绑定,因为我只需要SSL/端口443。因此,从我能看出的是,端口80绑定也是重写正常工作所必需的。

    除了配置中的错误之外,别忘了在Chrome的匿名窗口中进行实验,否则301重定向将被缓存。每次输入新的“匿名”窗口时,您都需要关闭并启动新的“匿名”窗口。
    redirectType=“seeOther”
    是解决方案。这毁了我的一天。这在我的3台服务器上都不起作用。这是我的问题。这对我有效。我使用另一个http端口2021发布了我的站点,并删除了http的默认80端口绑定。把它加回去对我有用。