IIS下
1、rewrite_amd64_zh-CN.msi安装
2、ASP.NET站可直接修改web.config。IIS控制台右键单击需要设置的站点,选择“浏览”,编辑Web.config文件。在system.webServer之间添加以下内容:
web.config
<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>
Nginx上把HTTP请求重定向到HTTPS请求
http {
server {
listen 80;
server_name example.com www.example.com;
# Redirect all port 80 (HTTP) requests to port 443 (HTTPS).
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/cert-crt.crt;
ssl_certificate_key /path/to/cert-key.key;
# all other site settings go here (e.g. ssl, logs, site root)
}
}