Custom Domains & www
The most common deployment mistake: only adding the apex domain and forgetting www.
The problem
Section titled “The problem”The _redirects file handles www -> non-www:
https://www.domain.com/* https://domain.com/:splat 301But this rule only fires if www.domain.com is a custom domain on the Cloudflare Pages project. If it isn’t:
- Browser requests
www.domain.com - Cloudflare’s DNS sees the request
- No Pages project is associated with this domain
- Cloudflare tries to proxy to an origin server
- No origin server exists -> 522 Connection Timed Out
The fix
Section titled “The fix”Add both domains as custom domains in the Pages project:
- Pages -> project -> Custom domains
- Add
domain.com - Add
www.domain.com
Cloudflare creates CNAME records for both automatically (if DNS is on Cloudflare).
DNS requirements
Section titled “DNS requirements”The domain’s nameservers must point to Cloudflare. For most clients, DNS is already managed in Cloudflare. If not:
- Add the domain to Cloudflare (free plan)
- Change nameservers at the domain registrar
- Wait for DNS propagation (up to 48h)
- Then add custom domains in Pages
Subdomains
Section titled “Subdomains”For additional subdomains (e.g. docs.domain.com):
- Create a separate Pages project for the docs site
- Add
docs.domain.comas a custom domain on that project - Cloudflare creates a CNAME:
docs -> <project>.pages.dev
Cloudflare provisions SSL certificates automatically for all custom domains. No manual certificate management. HTTPS is enforced.