Aliif Arief Homepage

How to Redirect Cloudflare Pages Domain to Custom Domain

By Aliif Arief ยท 1 minute

Hello folks,

You should know that until now, when this article was written, Cloudflare pages did not support redirecting the default domain to a custom domain that we have via the HTTP header. Hence, we have to overcome it by using JavaScript to redirect.

The following is the JavaScript code to redirect a domain to a domain without a dynamic relative path.

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

And below is the JavaScript code to redirect the domain to the domain with a dynamic relative path.

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

Replace the domain with your custom domain, then wrap one of the scripts with <script></script> tags and place them before the closing </head> tag on your web page.

Thank you for reading. If there are errors or questions, don’t hesitate to leave a comment.


โœ๏ธ at 17:00 on August 6, 2022
๐Ÿ†• at 17:00 on December 26, 2022

Normalisasi htdocs XAMPP di Ubuntu Mengenal Design Pattern