Your apex domain works and www does not
yourdomain.com loads perfectly. www.yourdomain.com does not resolve at all. Nothing in the dashboard shows an error.
Serving a hostname on Cloudflare Pages takes two independent things, and the interface makes it look like one.
The two steps
1. Attach the hostname to the Pages project. This tells Pages to answer for that name.
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT/pages/projects/$PROJECT/domains" \
-H "Authorization: Bearer $CF_TOKEN" -H "Content-Type: application/json" \
-d '{"name":"www.yourdomain.com"}'
2. Create the DNS record. The call above does not do this, and that is the entire bug:
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \
-H "Authorization: Bearer $CF_TOKEN" -H "Content-Type: application/json" \
-d '{"type":"CNAME","name":"www.yourdomain.com","content":"$PROJECT.pages.dev","proxied":true,"ttl":1}'
Do step one without step two and the hostname is registered with Pages while DNS has never heard of it. Queries return NXDOMAIN. Confirm with:
curl -s -H "accept: application/dns-json" \
"https://cloudflare-dns.com/dns-query?name=www.yourdomain.com&type=CNAME"
A "Status": 3 means the name does not exist, which points at step two, not at Pages.
Why this matters more than it looks
People type www. Other sites link to www. If www does not resolve, those visitors get a browser error rather than your site, and any link equity pointed at www is wasted. It is also the kind of gap that survives for months because the person who set the site up always types the apex.
The redirect, and the permission that blocks it
Ideally www issues a 301 to the apex so only one hostname is canonical. On Cloudflare that is a Redirect Rule, and creating one through the API needs the token to carry Rulesets permission. Without it the call fails with a generic authentication error that does not name the missing scope, which sends you off checking the token for problems it does not have.
If you cannot add that permission, serving both hostnames is perfectly acceptable as long as every page carries a canonical tag pointing at the apex. Search engines then consolidate on the apex on their own. Just make sure the canonical actually points where you think, which is its own trap: see when your canonical URL points at a redirect.
Add www at the same time as the apex, every time. It is thirty seconds during setup and an easily missed gap forever afterwards. On a six site network, every single site was missing www because the apex worked and nobody thought to check the other one.
Related
Your canonical tag points at a URL that redirects
A canonical ending in .html when the real URL is extensionless quietly undermines indexing.
DISCOVERYVerifying a Search Console domain property without handing Google your DNS
The one click Cloudflare option grants Google write access to all your DNS. The TXT route does not.
DISCOVERYYour site is deployed and Google does not know it exists
Deploying tells nobody. Without Search Console there is no indexing path and waiting will not create one.