我在SO以及'net(IIS博客等)上阅读了很多帖子。我正在尝试强制所有连接从domain.com到www.domain.com,同时强制请求从HTTP到HTTPS 。
我正在使用这套规则并重写,但唯一发生的事情是它重定向很好但没有重定向到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>
我做错了什么?
主要博客参考:http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action以及此SO帖子 - web.config redirect non-www to www
答案 0 :(得分:11)
编辑:所以我发现了这篇博文:http://www.meltedbutter.net/wp/?p=231并尝试了一下瞧!工作就像一个魅力。不确定为什么这可以解决上面发布的规则,但在我的情况下,以下工作并成功获取所有非www流量并将其重定向到 www 和 https 。< / p>
<!-- 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>
答案 1 :(得分:4)
我们在使用URL Rewrite模块从http重定向到https时遇到了同样的问题,但在关闭IIS中的require ssl模块之后就行了。
答案 2 :(得分:1)
对于某些情况来说这是一个很长的镜头,但是我已经删除了我的端口80绑定网站,因为我只想要SSL /端口443.所以从我可以告诉的是,端口80绑定也需要重写工作正确。