【记录】使用.htaccess将http重定向https

网站根目录创建 .htaccess文件

添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
会影响子域名(复制时候去掉本行):
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]


不会影响子域名,只有主域名重定向(复制时候去掉本行):
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} !^www.luojing.top
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]


排除某个子域名(复制时候去掉本行):
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^http://roc.luojing.top
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]