1.修改C:\inetpub\custerr\zh-CN\403.htm文件,在<head>标签中添加:
<script type="text/javascript">
var url=window.location.href;
url=url.replace("http:","https:")
window.location.replace(url);
</script>
IIS管理中SSL设置的“需要SSL”需要勾选,这样当访问不是http的页面时就会先跳转到403错误页面,然后再跳转到https页面。
2.对于asp.net站点,可以直接修改web.config配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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>
</configuration>