Hoping it's a stupid and basic question, but can't find the answer in Google, nor in search here.
Website setup:
Then introduced SSL, so now it's:
Have shared hosting with a cPanel (if it's relevant info) and using Cloudflare free package.
1) How can I make users typing:
example.com, and www.example.com be directly redirected (without several redirects) to https://www.example.com
2) Can I also make the following, for users typing:
sub.example.com as well as www.sub.example.com to be redirected to: https://sub.example.com
I have made it to work, but it took using two pagerules in CloudFlare. Is there a more clever and better solution?
What I've done so far:
DNS:
A mydomain.com points to hostIP
A sub points to hostIP
CNAME www alias of mydomain
CNAME www.sub alias of sub.mydomain.com
This alone didn't help, so I had to make two page rules in CloudFlare, in order:
www.sub.example.com/* - forwarding url 301 to https://sub.example.com/$1
example.com/* - forwarding url 301 to https://www.example.com/$1
I also set "Always use HTTPS" in CloudFlare Crypto settings.
Only total of 3 page rules with CloudFlare, one used to not cache admin when logged in. So a total of 2 to left to work with. Although I guess there is a better way to do it, is there?
From what I gather, setting it up in .htaccess is no longer considered a good policy, is it?
Thanks in advance for any help.