Cloudflare Pages DNS Configuration

I recently gained access to the Cloudflare Pages beta, and wanted to set it up for a new domain. For a new domain, what’s the suggested setup for DNS? If I add the domain as www.newdomain.com, it will create a CNAME for www., but then there is no A record created. Similarly, it seems setting up the domain as newdomain.com sets a CNAME that can be flattened, but there’s still no proper A record for the domain.

What’s the recommendation for this setup? And also, are there plans to make this a bit clearer via the Cloudflare Pages GUI?

Thanks!

As it’s been a couple of hours with no reply, I’ll give it a shot.

Then the flattened CNAME will behave as an “A” record and hopefully that will work for you. If not, use ‘www’. The following tutorial will show you how to add the opposite DNS record:

Yea he came to the discord a few hours ago and we help him set up a worker to do the redirect. His problem is solved!

Yes, I did get this solved!

For anyone who runs into this question in the future, here’s what I wound up doing:

  • Set up the Cloudflare Pages site to be at www.mydomain.com, and it created a CNAME record for www
  • Created an A record on the domain that points to 1.1.1.1
  • Created a Cloudflare Worker with the code included at the end of this reply.
  • Attached that worker to the route mydomain.com/*

All seems to be working well! Thanks!

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url);
  const { pathname } = url;

  console.log('Going to: ' + 'https://www.mydomain.com' + pathname);
  return Response.redirect('https://www.mydomain.com' + pathname, 301);
}

Why did you have to create a Worker to do the 301 redirect instead of a Page Rule?

Maybe that would work just as well? Set up the A record to 1.1.1.1 still, but set up a Page Rule to 301 redirect all domain.com/* to www.domain.com/$1 ?

That’s why I’d try. That way you wouldn’t have to pay for Workers, nor worry about exceeding your monthly allowance.

Great, the Page Rules solution worked as well! And I personally prefer the simplicity also.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.