Skip to content
Cloudflare Docs

Point to Pages with a custom domain

Last reviewed: 9 days ago

This example configures an origin rule and a DNS record to point to a Pages deployment with a custom domain.

The procedure will use the following example values:

URL that website visitors will accessmycustomerexample.com/blog/*
Zone domainmycustomerexample.com
Cloudflare Pages subdomainmyblog.pages.dev
Cloudflare Pages custom domainblogmirror.example.com

When configuring your Pages custom domain, use a custom domain that you do not plan to use in production (blogmirror.example.com in this example).

1. Configure custom domain in your Pages project

To add the custom domain to your Pages deployment:

  1. Log in to the Cloudflare dashboard and select your account.
  2. Go to Workers & Pages and select your Pages project.
  3. Go to Custom domains.
  4. Select Set up a custom domain.
  5. Enter blogmirror.example.com and select Continue.

When you add the custom domain to your Pages deployment, Cloudflare automatically creates a CNAME DNS record for the custom domain.

2. Create origin rule to rewrite host header and override DNS record

In your mycustomerexample.com zone, create an origin rule with the following configuration:

If incoming requests match

FieldOperatorValue
URI Pathwildcard/blog/*

If using the Expression Editor, enter the following expression:

(http.request.uri.path wildcard "/blog/*")

Set origin parameters

  • Value after Host header > Rewrite to: blogmirror.example.com
  • Value after DNS record > Override to: blogmirror.example.com

3. (Optional) Configure URL rewrite

In this example, the URL that website visitors will access starts with /blog. However, the Pages deployment does not have this initial URL segment.

Use a URL rewrite to remove the /blog segment from the URL path.

  1. Go to Rules > Overview.

  2. Select Create rule > URL Rewrite Rule.

  3. Enter a descriptive name for the rule in Rule name.

  4. In If incoming requests match, select Wildcard pattern.

  5. Enter the following value in Request URL:

    https://<YOUR_HOSTNAME>/blog/*

    In the current example, the value would be https://mycustomerexample.com/blog/*.

  6. In Then rewrite the path and/or query, enter the following values under Path:

    Target pathRewrite to
    [/] blog/*[/] ${1}
  7. Select Deploy.

More resources