DEV Community

Noor Aiman
Noor Aiman

Posted on

[Cloudflare] Redirect To Another Domain

If you've ever tried to redirect one domain to another using Cloudflare Page Rules and found yourself stuck, you’re not alone. I recently encountered the same roadblocks, despite carefully following Cloudflare's official documentation. Here’s what I did:

Following the Cloudflare guide on redirecting with Page Rules, I logged into my account, navigated to Rules > Page Rules, and created a new rule to forward the URL. I set the URL pattern, chose Forwarding URL with a 301 - Permanent Redirect, and entered my destination URL. Everything seemed correct, but the redirect just wouldn’t work!
Page Rules

After some head-scratching, I discovered the missing piece: Cloudflare’s DNS settings. If you’re redirecting an alias domain with no origin server, you need to configure a proxied DNS A or CNAME record for the domain.
Official Docs Redirect one domain to another
Cloudflare recommends using the IP 192.0.2.1 for the A record, which doesn’t actually route traffic but enables Cloudflare to apply redirects. Make sure to add this configuration for both the root domain and the www subdomain. You can find these instructions here.

Adding these DNS records finally made the redirect work, so if you’re stuck, this may be your missing link!

References:-

Top comments (0)