Working With Cloudflare Pages

I am experimenting with Cloudflare pages, and I assigned a domain name to the project and everything is great, except I want to make sure visitors can only access the domain name and not directly access the project itself. In other words they can only go my mydomain.com and cannot access 9999999.myproject.pages.dev directly. Is there a snippet of code that I can insert into the page that will prevent this, and could someone give me an example of what that code would look like?

Thanks for any help,

Hokey

If you want to keep it all in Cloudflare, then you can use an access policy.

https://developers.cloudflare.com/pages/platform/preview-deployments/#customizing-preview-deployments-access

1 Like

So, if I understood it correctly, I want the exact opposite. I only want access through the assigned domain, but not through Cloudflare directly (eg., 99999.myproject.pages.dev). The project is in production and not preview.

Sorry I should have clarified by keep it all in Cloudflare I mean by bring in Zero-Trust. I also had the wrong link

This instruction will protect your preview deployments and your *.pages.dev domain.
https://developers.cloudflare.com/pages/platform/known-issues/#enabling-access-on-your-pagesdev-domain

I am a little lost here. So I go to zero trust access and entered the correct domain information. I am now editing the policy. What should I enter to allow access on if the visitor enters the domain name and not the CF URL directly, so they can only enter mydomain.com and not myproject.pages.dev. I just tried the block policy and nothing happened.

Sorry, that actually solved the problem to include block everyone. Thanks!

1 Like

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