在這篇 IIS 使用 Let’s Encrypt 的 SSL 免費憑證 – 多站台申請 提到了免費SSL憑證申請,現在我們要申請完後要限制每個網站都只能用https瀏覽的話,就必須用web.config
來將使用者自動轉移到https的網址上,廢話不多說教學如下。
- 在要移轉的網域資料夾下新增檔案
web.config
,內容如下:
12345678910111213141516<?xml version="1.0" encoding="UTF-8"?><configuration><system.webServer><rewrite><rules><rule name="HTTP to HTTPS redirect from:https://blog.exfast.me" 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></configuration>
新增完畢後無須重啟立即生效,現在輸入http網址看看會不會轉跳到https吧!