将http重定向到https的方法:
1. 如果你用的是 apache 服务器,可以在 .htaccess
文件中添加以下规则:
(ps: 以下规则需要开启 Apache 的 mod_rewrite
模块才能生效)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
2. 如果你用的是 nginx 服务器,需要更改nginx的配置文件,请参考以下方法,
server {
listen 80;
server_name yourdomain.com;
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
# 其他配置项...
}
更改nginx的配置文件之后,需要重新加载或重启 Nginx 服务器,配置才会生效。