Redirect Cloudflare Pages Domain to Custom Domain

Hi Everyone. Is there any way to redirect from cloudflare pages domain to custom domain?
So I want to redirect all the visitor when visiting to to

Other than coding something into the site itself, I think you’re stuck. You can’t do it through Page Rules (I tried). @sandro might know a quick JS file you can add that will force a site to reload a different URL if your visitor is on the site.

Or I could be completely wrong and it’s not possible.

1 Like

Add this JS snippet:

    if (window.location.hostname !== ""){ = '';

to the header and replace “” with the real full domain (eg. without scheme!). It will redirect all your traffic to the domain you want.

1 Like

Thank you for this solution, I think there’s no other option to do redirection before browser render the pages instead we can do client side redirection.

As you do not controll the domain “” there normaly is no option, unless there is/will be an option in Cloudflare Pages settings that allows a redirect to the confirmed custom domain.

But I think the main goal is it to just not publish “” so noone ever knows about this and then there is basically no chance people are hitting this URL/Domain

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