Skip to content

Custom Domains & www

The most common deployment mistake: only adding the apex domain and forgetting www.


The _redirects file handles www -> non-www:

https://www.domain.com/* https://domain.com/:splat 301

But this rule only fires if www.domain.com is a custom domain on the Cloudflare Pages project. If it isn’t:

  1. Browser requests www.domain.com
  2. Cloudflare’s DNS sees the request
  3. No Pages project is associated with this domain
  4. Cloudflare tries to proxy to an origin server
  5. No origin server exists -> 522 Connection Timed Out

Add both domains as custom domains in the Pages project:

  1. Pages -> project -> Custom domains
  2. Add domain.com
  3. Add www.domain.com

Cloudflare creates CNAME records for both automatically (if DNS is on Cloudflare).


The domain’s nameservers must point to Cloudflare. For most clients, DNS is already managed in Cloudflare. If not:

  1. Add the domain to Cloudflare (free plan)
  2. Change nameservers at the domain registrar
  3. Wait for DNS propagation (up to 48h)
  4. Then add custom domains in Pages

For additional subdomains (e.g. docs.domain.com):

  1. Create a separate Pages project for the docs site
  2. Add docs.domain.com as a custom domain on that project
  3. Cloudflare creates a CNAME: docs -> <project>.pages.dev

Cloudflare provisions SSL certificates automatically for all custom domains. No manual certificate management. HTTPS is enforced.