网站启用ssl后,怎么将http自动跳转https呢?下面介绍.htaccess实现方法

一、非www跳转www并跳转https

在你网站目录下放一个.htaccess文件,编辑器打开.htaccess文件,写入如下规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^minirizhi.com [NC]
RewriteRule .* http://www.minirizhi.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

二、www跳转https非www

编辑器打开.htaccess文件,写入如下规则:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^minirizhi\.com$ [NC]
RewriteRule .* http://minirizhi.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
文章目录