cruntrix
BUILDTUTORIAL

How to add a custom domain to Cloudflare Pages

Move your site from project.pages.dev to your own domain in a few minutes. The steps for a domain already on Cloudflare, a subdomain elsewhere, and redirecting www and pages.dev.

Research-based: specs + published reviews

Cover reading Custom domain on Cloudflare Pages, with a terminal window illustration

Every Cloudflare Pages project gets a free address like my-site.pages.dev. It works, but you’ll want your own domain before you share the site. This tutorial shows you how to add a custom domain to Cloudflare Pages, whether your domain is already on Cloudflare or not, and how to send visitors from the old addresses to the new one.

What you need

Add the domain in Pages first

  1. In the Cloudflare dashboard, go to Workers & Pages and select your Pages project.
  2. Open the Custom domains tab and select Set up a custom domain.
  3. Type the domain or subdomain, such as example.com or blog.example.com, and select Continue.
  4. Select Activate domain.

Add the domain here before you touch DNS. A DNS record that points at your pages.dev address without the domain added to the project won’t serve your site.

If the domain’s DNS is on Cloudflare

This is the easy case. When you activate the domain, Cloudflare creates the DNS record for you, a CNAME pointing to your project.pages.dev address, and issues an SSL certificate automatically. For an apex domain, Cloudflare handles the fact that a root domain normally can’t have a CNAME by “flattening” it behind the scenes. Wait a few minutes and the status changes to Active.

If the DNS is somewhere else (subdomains only)

You can use a subdomain such as www.example.com or blog.example.com while keeping your DNS at another provider:

  1. Add the subdomain in Custom domains as above.
  2. At your DNS provider, create a CNAME record: name blog (or www), target your-project.pages.dev.
  3. Back in Cloudflare, wait for the domain to show as Active. This can take longer than on Cloudflare DNS.

For the root domain itself, you’ll need to move the domain’s nameservers to Cloudflare. Your registrar’s control panel has a setting for nameservers; Cloudflare shows the two names to enter when you add the domain to your account.

Redirect www and pages.dev to one address

Search engines prefer one address per page. Pick your main version, example.com or www.example.com, and send everything else there with a permanent (301) redirect:

Path-level redirects, such as old post URLs, are handled differently, with a _redirects file in your site; see our guide to redirects on Cloudflare Pages.

Common mistakes

FAQ

How long does it take for the domain to work?

If the domain is already on Cloudflare, usually a few minutes, including the security certificate. If you've just moved your nameservers to Cloudflare, it can take longer while the change spreads, occasionally up to a day.

Can I use the same domain on two Pages projects?

Not the same hostname, but different subdomains can point to different projects, for example the main site on example.com and a docs project on docs.example.com.

SOURCES

Nate ArdenEditor of Cruntrix. Edits every article before it goes up and writes the Build section.