I'm trying to redirect all HTTP traffic to HTTPS including subdomains. I have the domain setup with FastComet on their Shared Hosting using cPanel. Some examples of how I like to redirect.
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
I've tried adding below to my .htaccess file
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.+\.)?mydomain\.com$
RewriteRule ^(.*)$ https://%1mydomain.com/$1 [R=301,L]
And the more general
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But none of them redirects http://mail.example.com to https://mail.example.com while redirecting http://example.com/mail to https://example.com/mail works. What is it I'm missing my setup?