Force example.com to https://www.example.com

ssl

#1

Currently if I type mysite[dot]com or www.mysite[dot]com it redirects to https://mysite[dot]com
However I want it to redirect to https://www.mysite.com
I have created page rule also but none of them is working.


#2

First of all, it’s important to understand that in order for a page rule to work the DNS record that is in your page rule pattern (e.g. mysite.com) must be orange-clouded in your Cloudflare DNS. If it is not, then Cloudflare will never receive that traffic, nor will it be able to redirect it.

I would recommend enabling “Always Use HTTPS” in your Crypto settings, this will force all traffic automatically to HTTPS, then you can add the following:

URL Pattern: https://mysite.com/*
301 Forward To: https://www.mysite.com/$1

Since Always Use HTTPS forces traffic to HTTPS you don’t need a second page rule to capture HTTP.


#3

Thank you for a quick reply. I have already orange clouded my DNS in cloudfare. And I am using “Always use HTTPS”. And then added the rule that you have said. but when I type www.mysite.com it says this page is not working,
while when i type only mysite[dot]com it redirects to non-www and https.


#4

OK - can you give the exact URL? It’s hard to troubleshoot without the specifics in this case.


#5

#6

OK, so this is an origin issue:

< HTTP/2 302
< date: Wed, 08 Aug 2018 10:29:43 GMT
< content-type: text/html
< set-cookie: __cfduid=d96c0ce6e3355db4ff83a83a97b615e3d1533724183; expires=Thu, 08-Aug-19 10:29:43 GMT; path=/; domain=.islatials.com; HttpOnly; Secure
< x-powered-by: PHP/5.5.9-1ubuntu4.25
< location: https://islatials.com/
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 44714db07f016a4f-LHR

You can see there that the origin is returning a HTTP 302 back to https://islatials.com/. The clue here is the x-powered-by: PHP/5.5.9-1ubuntu4.25 header that tells me Cloudflare went to your origin to return this response.

You will need to disable this redirect on your origin server, then everything should work just fine.

For future reference, you can compare a response with/without Cloudflare using cURL which is a useful tool to help diagnose: