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:-

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay