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:


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.

  • Sorry but we already have a range of questions and answers regarding non-ssl to ssl, including subdomains to main domain. Please use the search feature and visit our help centre for further assitance. Commented Sep 11, 2018 at 13:29
  • 1
    You can also find help regarding page rules redirects using cloudflare, for example http://example.com/* > https://www.example.com/$1, https://example.com/* > https://www.example.com/$1, https://sub-domain.example.com/* > https://www.example.com/$1. If your limited by page rules, upgrade, since minor page redirects like these are best handled by Cloudflare because of its one less server-side request or handle just the sub domain by the htaccess. Commented Sep 11, 2018 at 13:34
  • That's sort of the answer I was looking for - better off using cloudflare than configuring things server-side? In that case I'm set - since I've only managed to make it work using cloudflare. :) Thanks. P.S. Having trouble finding the straight answer with google, or this community. Didn't see it answered before, that's why I posted the question. Commented Sep 11, 2018 at 19:18


Browse other questions tagged or ask your own question.