如何将我的所有子域从http重定向到https

时间:2019-06-23 20:31:17

标签: .htaccess

所以我在htaccess中有以下代码:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.no
RewriteRule ^(.*)$ https://www.mydomain.no/ [R,L]

但是,当我输入(m.mydomain.no)这样的子域时,它不会重定向到https,我该如何解决?谢谢

1 个答案:

答案 0 :(得分:0)

检查此规则,对于http子域(非www),第二次:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.no
RewriteRule ^(.*)$ https://www.mydomain.no/ [R,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]