我正在尝试将所有HTTP流量重定向到HTTPS包括子域。我使用 cPanel 在他们的共享主机上使用 FastComet 设置了域。我喜欢重定向的一些例子。
http://www.example.com -> https://www.example.com
http://example.com -> https://example.com
http://www.example.com/mail -> https://www.example.com/mail
http://example.com/mail -> https://example.com/mail
http://mail.example.com -> https://mail.example.com
Run Code Online (Sandbox Code Playgroud)
我试过在我的.htaccess文件中添加以下内容
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.+\.)?mydomain\.com$
RewriteRule ^(.*)$ https://%1mydomain.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
而且更一般
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Run Code Online (Sandbox Code Playgroud)
但他们没有重定向http://mail.example.com到https://mail.example.com,同时重定向http://example.com/mail到https://example.com/mail的作品。我缺少什么设置?