IIS7下站點(diǎn)實(shí)現(xiàn)從http跳轉(zhuǎn)https
2018-04-13 17:43:27
11211
若一個(gè)站點(diǎn)同時(shí)可通過http和https訪問,但需要實(shí)現(xiàn)點(diǎn)擊http跳轉(zhuǎn)https的效果,該如何實(shí)現(xiàn)?
答案是在Web.config添加以下代碼實(shí)現(xiàn)http跳轉(zhuǎn)到https:
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
注意:若Web.config已有內(nèi)容,則在配置文件web.config中添加<rewrite>到</rewrite>部分即可