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 xxx.pages.dev
to mydomain.com
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 .pages.dev site.
Or I could be completely wrong and it’s not possible.
Add this JS snippet:
<script>
if (window.location.hostname !== "www.mydomain.com"){
window.top.location.href = 'https://www.mydomain.com';
}
</script>
to the header and replace “www.mydomain.com” with the real full domain (eg. www.domain.com without scheme!). It will redirect all your traffic to the domain you want.
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 “pages.dev” 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 “xxx.pages.dev” 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.