C# MVC站点 (安装SSL证书后) 实现 HTTP自动跳转到 HTTPS的Web.config设置方法
1、IIS 里 安装好 SSL 证书后,如何实现 在浏览器里录入 http://www.xxx.com,会自动跳转到 https://www.xxx.com 呢。
首先,下载并安装 IIS 扩展: URL重写(URL Rewrite)扩展
URL重写扩展下载地址: https://www.iis.net/downloads/microsoft/url-rewrite
2、Web.config配置
<system.webServer> <rewrite> <rules> <clear /> <rule name="Redirect to https" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> </rule> </rules> </rewrite> </system.webServer>
释疑:
redirectType="Found"和redirectType="Permanent"哪个是301哪个是302?
redirectType="Permanent"表示永久转向,也就是301重定向。
而redirectType="Found"则是丢失的文件找到了的意思,是临时重定向,也就是302重定向。
微信号:jamesworkshop 学习QQ群:364976091