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 and cannot access 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,


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

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., 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 * 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 and not 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.