So I’ve been messing around with Cloudflare tonight and believe I’ve got it all sorted out. For anybody in the future who is reading this, here is what you do:
-
Create a free Cloudflare account.
-
Click on “Websites” on the sidebar and add your domain.
-
It should auto detect all of your existing DNS settings and then provide you with two new addresses. Go into Namecheap, manage your domain, and then under “Nameservers” you’re going to select “Custom DNS”. That is where you then enter the two new nameserver addresses.
Took about 3-5 minutes for propagation to complete but once it did, Cloudflare immediately took over with all of my DNS settings in place. To be clear, my domain is still though Namecheap, I’m just now using Cloudflare to manage the DNS settings.
- While still in your Website settings on Cloudflare, click on Rules > Page Rules in the sidebar.
- In the “If the URL matches” field, enter:
http://*yourdomain.com/*
andhttps://*yourdomain.com/*
(You might need to create two separate rules for http and https versions) - From the “Then the settings are:” dropdown, choose “Forwarding URL.”
- From the next dropdown that appears, choose “301 - Permanent Redirect.”
- In the text field that appears, enter
https://www.yourdomain.com/$1
- Click on “Save and Deploy.”
NOTE: Adding the $1 after the / is important because it’s a wildcard. Otherwise if someone typed in domain.com/blog
it would just redirect to www.domain.com
. By adding the $1, domain.com/blog
would redirect to www.domain.com/blog
.
After that my own devices took about 30 minutes to see a working change. However, up until then I could see pretty quickly that it was redirecting properly by using tools like httpstatus.io which showed me it was working.
Problem now solved and I feel like the initial page load when visiting the site is way snappier, but perhaps that’s all in my head