5

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?

g3blv
  • 279

2 Answers2

0

If this is a reasonably recent Apache. This ability can be achieved in extra/http-vhosts.conf. But your ability to accomplish the following in .htaccess will be completely dependent on your hosting providers willingness to let you do so.

If you place the following in the .htaccess file at the root of your server(s). It should accomplish your goal:

ServerName MyServer.COM
Redirect permanent / https://myserver.com/

All this does is send a 301 permanent. So you won't get penalized by google (if you care), and browser bookmarks, and other clients will become cluefull of the change.

It's pretty simple to understand. So I won't elaborate further.

Good luck!

Giacomo1968
  • 58,727
somebody
  • 560
0

Nothing to change just copy and paste.

RewriteEngine On   
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Giacomo1968
  • 58,727