使用 .htaccess 强制 HTTPS
适用于 Apache 或支持 .htaccess 的主机环境。
将以下规则加入网站根目录的 .htaccess:
apache
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]保存后访问 http://example.com,应自动跳转到 https://example.com。