![](/img/trans.png)
[英]IIS 8.5 URL Rewrite force redirect http --> https for non www
[英]HTTP to HTTPS Redirect - IIS 8.5 not working properly
我在這里閱讀了許多關於 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 將非 www 重定向到 www
編輯:所以我找到了這篇博文: http : //www.meltedbutter.net/wp/? p=231 並嘗試了一下,瞧! 像魅力一樣工作。 不知道為什么這對上面發布的規則有效,但在我的情況下,下面的規則可以正常工作並成功獲取所有非 www 流量並將其重定向到www和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>
我們在使用 URL Rewrite 模塊從 http 重定向到 https 時遇到了同樣的問題,但是在關閉 IIS 中的 require ssl 模塊后,我們遇到了同樣的問題。
在某些情況下,這是一個很長的鏡頭,但我已經刪除了網站的端口 80 綁定,因為我只想要 SSL/端口 443。所以據我所知,端口 80 綁定也需要重寫才能正常工作。
就我而言,我做了@Valien 所說的一切以及許多其他嘗試,但沒有奏效。 最后我發現了問題。 這是因為我使用了 2 條規則。 第一條規則是重寫到 NodeJs 服務器,第二條是將 http 重定向到 https。我更改了順序,現在它工作正常。
如果應用了超過 1 個規則,則具有正確順序的配置:
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mywebsite.com/{R:1}" redirectType="SeeOther" />
</rule>
<rule name="ReverseProxyToLocalhost:3000" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
</rules>
</rewrite>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.