Custom Domains, Worker Routes, DNS Records and workers.dev
How Cloudflare Pages and Workers connect custom hostnames: Custom Domains vs Routes, CNAME setup, apex zones, branch aliases, and common failures.
This page summarizes Cloudflare documentation on pointing your own hostnames at Cloudflare Pages sites and Cloudflare Workers, and on choosing between Custom Domains, routes, and workers.dev. The same hostname ideas also appear on products such as AI Gateway, but the setup paths below focus on Pages and Workers—the subjects most of the official guides cover.
Custom domains on Pages: what they do and when you need them
Section titled “Custom domains on Pages: what they do and when you need them”Cloudflare Pages custom domains let you serve a deployed site on a hostname you control (apex or subdomain) instead of only on *.pages.dev.
When deploying your Pages project, you may wish to point custom domains (or subdomains) to your site.
— Cloudflare, Custom domains (Pages)
You typically add a custom domain when the site is ready for production branding, when you migrate from another host, or when you need zone-level settings (caching, rules) to apply on a proxied record.
pages.dev custom domain: dashboard setup (apex vs subdomain)
Section titled “pages.dev custom domain: dashboard setup (apex vs subdomain)”To register the hostname on the project:
- In the Cloudflare dashboard, open Workers & Pages and select your Pages project (Custom domains).
- Choose Custom domains → Set up a domain, enter the hostname, and continue through activation.
- Finish DNS as described in the next sections—either nameservers on Cloudflare or a CNAME at your DNS provider.
Apex (e.g. example.com): the domain must be a zone on the same Cloudflare account as the Pages project, with nameservers pointed to Cloudflare; Cloudflare can then create the needed records (Configure nameservers).
Subdomain only: the site does not have to be a full Cloudflare zone. You can add a CNAME at an external DNS provider—but you must still complete Add a custom domain in Pages first (Add a custom subdomain).
If you do not want to point your nameservers to Cloudflare, you must create a custom CNAME record to use a subdomain with Cloudflare Pages. After logging in to your DNS provider, add a CNAME record for your desired subdomain, for example, shop.example.com. This record should point to your custom Pages subdomain, for example,
<YOUR_SITE>.pages.dev.
— Cloudflare, Add a custom CNAME record
Unlike Workers, Pages can use a subdomain whose nameservers are not on Cloudflare (Migrate from Pages to Workers).
Branch custom domain (staging hostname on one branch)
Section titled “Branch custom domain (staging hostname on one branch)”For a hostname that always shows the latest build of a specific branch (not production), use Add a custom domain to a branch:
This setup is only supported when using a proxied Cloudflare DNS record.
If you attempt to follow this guide using an external DNS provider or an unproxied DNS record, your custom alias will be sent to the production branch of your Pages project.
After activating the custom domain in Pages, edit the zone CNAME so the target includes the branch alias—for example change your-project.pages.dev to staging.your-project.pages.dev.
Workers: Custom Domains, routes, and workers.dev
Section titled “Workers: Custom Domains, routes, and workers.dev”To accept HTTP traffic, a Worker must be attached to an Internet-facing endpoint. Cloudflare defines three routing types:
There are three types of routes: Custom Domains, routes, and workers.dev.
— Cloudflare, Wrangler configuration — Types of routes
| Mechanism | Worker role | DNS / certificate work | Typical use |
|---|---|---|---|
| Custom Domain | Worker is the origin (all paths on that hostname) | Cloudflare creates DNS records and certificates for you | APIs and apps with no separate origin server |
Route (pattern + zone) |
Worker runs in front of an existing proxied origin | You need a proxied (orange-cloud) DNS record for the hostname | Middleware, auth, logging before fetch() to origin |
| workers.dev | Default dev hostname per Worker | Account workers.dev subdomain |
Quick tests; not recommended for production |
Custom Domains allow you to connect your Worker to a domain or subdomain, without having to make changes to your DNS settings or perform any certificate management.
— Cloudflare, Custom Domains (Workers)
Routes allow users to map a URL pattern to a Worker. A route can be configured as a zone ID route, a zone name route, or a simple route.
— Cloudflare, Wrangler configuration — Routes
It’s recommended to run production Workers on a Workers route or custom domain, rather than on your workers.dev subdomain. Your workers.dev subdomain is treated as a Free website ↗︎ and is intended for personal or hobby projects that aren’t business-critical.
— Cloudflare, Routes and domains
Unlike Pages, Workers custom domains only work for domains that are zones on your Cloudflare account (Migrate from Pages to Workers).
When to choose Custom Domain vs route
Section titled “When to choose Custom Domain vs route”Custom Domains are recommended if you want to connect your Worker to the Internet and do not have an application server that you want to always communicate with.
— Cloudflare, Custom Domains — Background
Routes are recommended for you if you have a designated application server you always need to communicate with. Calling fetch() on the incoming Request object will trigger a subrequest to your application server, as defined in the DNS settings of your Cloudflare zone.
— Cloudflare, Routes — Background
workers.dev: enable, disable, and naming limits
Section titled “workers.dev: enable, disable, and naming limits”Format: <WORKER_NAME>.<ACCOUNT_SUBDOMAIN>.workers.dev (workers.dev). Set workers_dev in Wrangler; if you add routes without setting it, Wrangler infers workers_dev = false on the next deploy (Disabling workers.dev in the Wrangler configuration file).
Legacy wrangler subdomain and wrangler route CLI commands are deprecated; use the dashboard and Wrangler config instead (Deprecations).
Wrangler: custom_domain, zone routes, and wildcards
Section titled “Wrangler: custom_domain, zone routes, and wildcards”Custom Domain in Wrangler (custom_domain = true)
Section titled “Custom Domain in Wrangler (custom_domain = true)”To configure a Custom Domain in your Wrangler configuration file, add the custom_domain=true option on each pattern under routes.
— Cloudflare, Set up a Custom Domain in your Wrangler configuration file
Example (hostname only, no /* required for Custom Domains):
{ "routes": [ { "pattern": "shop.example.com", "custom_domain": true } ]}Deploy with npx wrangler deploy after DNS/route changes (Migrate from Routes via Wrangler).
Matching: Custom Domains require an exact hostname match; they do not use wildcard DNS records. Path and query are not part of hostname matching—api.example.com/login and api.example.com/user hit the same Worker (Request matching behaviour).
Zone ID, zone name, and simple routes
Section titled “Zone ID, zone name, and simple routes”For a route (not Custom Domain), set pattern with a path wildcard when needed, plus zone_name or zone_id (Set up a route in the Wrangler configuration file):
[[routes]]pattern = "subdomain.example.com/*"zone_name = "example.com"Sandbox preview on your own domain uses a wildcard pattern such as *.yourdomain.com/* with zone_name (Configure preview URLs on a custom domain).
Use either legacy single route or routes array—not both (Publishing to your own domain).
DNS records: proxied CNAME, apex, and API-created targets
Section titled “DNS records: proxied CNAME, apex, and API-created targets”Pages and proxied records
Section titled “Pages and proxied records”If the custom domain is proxied through Cloudflare, zone settings such as caching apply (Debugging Pages). Cloudflare Pages linking does not rely on publishing A/AAAA IPs for the project—CNAME to *.pages.dev is the documented model (Migrating from Vercel to Pages — Troubleshooting).
AI Gateway pattern (API + manual CNAME)
Section titled “AI Gateway pattern (API + manual CNAME)”For AI Gateway custom domains, the API returns cname_target; you create a proxied CNAME yourself. The hostname stays pending_dcv until domain control validation completes.
Worker Custom Domain constraints
Section titled “Worker Custom Domain constraints”You cannot create a Custom Domain on a hostname with an existing CNAME DNS record or on a zone you do not own.
— Cloudflare, Add a Custom Domain
For routes, every hostname must have a proxied DNS record or visitors get ERR_NAME_NOT_RESOLVED (Domains and subdomains must have a DNS Record). If you used a placeholder AAAA to 100::, Cloudflare recommends migrating to a Custom Domain instead (Routes — caution).
www and apex on Workers Custom Domains
Section titled “www and apex on Workers Custom Domains”example.com and www.example.com are different Custom Domains. Use redirect rules plus proxied placeholder A/AAAA records (192.0.2.0 / 100::) so Cloudflare can apply redirects without reaching those addresses.
Known limits, SSL validation, and common mistakes
Section titled “Known limits, SSL validation, and common mistakes”Pages custom domain restrictions
Section titled “Pages custom domain restrictions”From Known issues — Custom Domains:
- No wildcard custom domains (e.g.
*.domain.com). - Cannot add if a Worker is already routed on that domain.
- Cannot add if Cloudflare Access is already enabled on that domain in conflicting ways.
- Load Balancer does not work with
*.pages.dev; Error 1000 can appear. - SSL validation needs HTTP access to
http://{domain_name}/.well-known/acme-challenge/*(watch Access/Worker blocks). - Advanced Certificates are not supported on Pages (certificate prioritization).
Do not repoint DNS away from Pages casually
Section titled “Do not repoint DNS away from Pages casually”Once a custom domain is set up, if you change the DNS entry to point to something else (for example, your origin), the custom domain will become inactive.
— Cloudflare, Change DNS entry away from Pages and then back again
Prefer Origin rules or redirect rules for temporary routing instead of breaking the Pages CNAME.
Routing mistakes (Workers)
Section titled “Routing mistakes (Workers)”| Mistake | What goes wrong | What docs recommend |
|---|---|---|
| Route without proxied DNS | ERR_NAME_NOT_RESOLVED |
Proxied record or Custom Domain (Workers Best Practices) |
Worker as only origin but using /* route + manual CNAME |
Extra DNS complexity | Migrate to Custom Domain (Migrate from Routes) |
Production on workers.dev |
Treated as Free website tier | Custom Domain or route (workers.dev) |
| Pages CNAME only, skip dashboard | 522 errors | Register domain in Pages first (Custom domains) |
| Branch alias without proxied DNS | Traffic goes to production branch | Proxied CNAME + branch target (custom-branch-aliases) |
Hiding *.pages.dev and canonical URLs
Section titled “Hiding *.pages.dev and canonical URLs”You can redirect <project>.pages.dev to your custom domain with Bulk Redirects, or restrict preview/pages.dev access with Cloudflare Access (separate Access applications for custom hostname vs *.pages.dev when both are protected).
How to check this on your site
Section titled “How to check this on your site”- In Workers & Pages, confirm the hostname appears under Custom domains (Pages) or Settings → Domains & Routes (Workers), matching Pages custom domains or Worker Custom Domains.
- In DNS → Records, verify a proxied CNAME (or apex setup per docs) points to the correct
*.pages.dev, branch alias, or APIcname_targetas in Add a custom CNAME record. - Request the site over HTTPS; if activation stalls, check SSL DCV and
/.well-known/acme-challenge/reachability per Known issues. - Compare behaviour on
pages.dev/workers.devvs the custom hostname; if only the custom name fails, try the grey-cloud diagnostic step in Debugging Pages and review zone Page Rules that cache everything. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.