HTTP到HTTPS重定向 - IIS 8.5无法正常工作 [英] HTTP to HTTPS Redirect - IIS 8.5 not working properly
问题描述
我在SO以及'net(IIS博客等)上阅读了很多帖子。我正在尝试强制所有连接从domain.com到www.domain.com,同时强制请求从HTTP到HTTPS 。
I've read a number of posts here on SO as well as on the 'net (IIS blogs, etc.). I'm trying to force all connections going from domain.com to www.domain.com and at the same time forcing the request from HTTP to HTTPS.
我正在使用这套规则并重写,但唯一发生的事情是它重定向很好但没有重定向到SSL。
I'm using this set of rules and rewrites but the only thing happening is that it's redirecting fine but not redirecting to 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将非www重定向到www
Main blog reference: http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action and this SO post - web.config redirect non-www to www
推荐答案
编辑:所以我发现这篇博文: http://www.meltedbutter.net/wp/?p=231 并尝试了一下瞧!工作就像一个魅力。不确定为什么这可以解决上面发布的规则,但在我的情况下,以下工作并成功获取所有非www流量并将其重定向到 www 和 https 。
So I found this blog post: http://www.meltedbutter.net/wp/?p=231 and gave it a try and voila! Worked like a charm. Not sure why this worked over the rules posted above but in my case the below is working and successfully taking all non-www traffic and redirecting it to both www and 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>
这篇关于HTTP到HTTPS重定向 - IIS 8.5无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!