介绍一下Apache环境下如何http强制跳转https访问。
Nginx环境下一般是通过修改“域名.conf”文件来实现的。而Apache环境下通过修改.htaccess 配置文件来设置。
设置方法
下面规则中使用的域名是www.it888.top或it888.top,使用时请根据自己需要更改为自己的域名。至于规则放置到什么位置,一般我们可以选择放到到apache的conf配置文件对应位置,或指定站点目录 .htaccess 文件内容的头部。
1、强制HTTPS方式访问,对WWW或顶级域名不做跳转。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.it888.top/$1 [L,R=301]
2、强制HTTPS方式访问,并自动将顶级域名跳转到WWW。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.it888.top$ [NC]
RewriteRule ^(.*)$ https://www.it888.top/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.it888.top/$1 [L,R=301]
3、强制HTTPS方式访问,并自动将WWW跳转到顶级域名。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^it888.top$ [NC]
RewriteRule ^(.*)$ https://it888.top/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://it888.top/$1 [L,R=301]