修改Apache相关配置文件,强制所有http跳转到https,假设网站域名为xxx.com。
1、在httpd-ssl.conf中
DocumentRoot “D:/web/xxx”
ServerName xxx.com:443
ServerAdmin admin@example.com
ErrorLog “D:/xampp/apache/logs/xxx_https_error.log”
TransferLog “D:/xampp/apache/logs/xxx_https_access.log”
2、在httpd-vhosts.conf文件的虚拟域名配置增加以下内容:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
这样,当输入 www.xxx.com 访问网站时,会自动跳转到 https://www.xxx.com
完整的
Options FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
ServerAdmin 877040117@qq.com
DocumentRoot “D:/web/xxx”
ServerName www.xxx.com
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
ErrorLog “logs/xxx-error.log”
CustomLog “logs/xxx-access.log” common