If example.com is my canonical URL, how should I redirect www.example.com traffic to it with DNS?

Currently, I have two sets of DNS rules set up, one for www.example.com, and one for example.com. So far I have a Page Rule that just redirects www.example.com/* to example.com/$1. If I didn’t have that page rule set up, my website would be accessible at both URLs, which from my research is bad. From my limited knowledge, it seems that most sites only have one set of DNS rules, then somehow redirect to their canonical site. However, when I disable my www.example.com rules, I can no longer access the site, and am forced to renter the URL so it reads example.com.

My questions:
Is having two sets of rules bad? (one for example.com and another for www.example.com)
What is the proper way to redirect traffic, and set up DNS so that www.example.com ends up at example.com?

Sorry if this is messy, this is my first time messing around with stuff like this.

Hi @brandonesser435!

Having two DNS records, one for the zone apex (example.com) and one for www.example.com, is perfectly fine and the standard way of configuring something like that. You don’t need to put the same IP address in both records: the “www” record could instead be a CNAME to example.com.

Without a DNS record, a browser trying to visit www.example.com won’t be able to find a web server to talk to, so the Page Rule configured at the server (in this case, Cloudflare) would never take effect.

Hope that helps! Let us know if you have any other questions.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.