How to setup www and non-www DNS with redirect on CloudFlare Pages websites (2025)

Quick post to help people struggling with this. First make sure you domain is added to CloudFlare DNS. Theres a standard process where you add the domain, change the nameservers, etc. This part is well documented and easy. Then you need a CloudFlare pages website. Again thats something you can find tutorials for.
Once you have both of these, you should check the DNS records of your domain. There might be some junk records from previous hosting. For example a lot of registrars will park your domain and have a landing page for it when you visit the site. This will show as an A record with an ip address. You can delete this if its there.
Typically you can delete all DNS records if you like. Ok, then to go the CloudFlare Pages site, go to custom domains, add your domain WITH www. in front of it. Then add it AGAIN, without the www. CF will prompt you on the DNS record its creating.
Your site will now work, but served in 2 places, www and non www. Its best to redirect one to the other. People mostly choose the naked domain, but its up to you.
https://www.rust-lang.org/
https://nodejs.org/en
^ Examples of both.
Ok so in CF, go to your homepage, Account home, and it will show all your domains. Click the one you’re using and on the left sidebar is “Rules”. Find redirect rule or find the template “Redirect from WWW to Root” OR “Redirect from Root to WWW“. If you want a url like nodejs.org, choose the first one.
Click create rule then all the default options should be correct. Wildcard pattern, 301. You don’t need to make any changes.
After you’ve saved this the job is done. Now your domain is perfectly setup.
Subscribe to my newsletter
Read articles from Brandon Lazenby directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
