1、下载安装URL重写模块:Microsoft URL Rewrite Module
- 32位:
http://download.microsoft.com/download/4/9/C/49CD28DB-4AA6-4A51-9437-AA001221F606/rewrite_x86_zh-CN.msi - 64位:
http://download.microsoft.com/download/4/E/7/4E7ECE9A-DF55-4F90-A354-B497072BDE0A/rewrite_x64_zh-CN.msi
2、IIS 10 安装 URLRewrite 组件方式:
- Open Regedit > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp
- Edit "MajorVersion" and set the "DECIMAL" value to 9
- Hit F5 while in Regedit
- Now go install the ReWrite 2.0 module.
- Change the "MajorVersion" back to "DECIMAL" value of 10
- Hit F5 while in Regedit
- Close Regedit
3、SSL设置,取消勾选“要求SSL”(很重要)
4、web.config 添加
<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>
5、设置301重定向
要实现对主域名访问(即:domain.com)自动跳转到带www的二级域名(即:www.domain.com),则可以新建一个空目录网站,并绑定不带www的主域名之下。最重要的是对这个绑定了主域名的空目录网站做301永久重定向。如图:
也可以通过"web.config"文件直接配置HTTP重定向。