How to Redirect a Domain Using Cloudflare Redirect Rules (Best Practice for Root + WWW, HTTP + HTTPS)

Andy

Well-known member
Creative Team
User ID
1
Joined
7 Jan 2019
Messages
1,766
Reaction score
145
Points
63
If you want to redirect one domain to another properly using Cloudflare, this guide shows the recommended modern best practice using Cloudflare Redirect Rules.

This is one of the most common scenarios website owners face. Sometimes a business changes its name and moves to a new domain. Sometimes multiple domains are consolidated into one main website. In other situations, an older domain still receives traffic from Google, backlinks, bookmarks, or previous customers, so redirecting it properly becomes important for both SEO and user experience.

In this example, we will redirect both olddomain.tld and www.olddomain.tld

including both HTTP and HTTPS traffic to https://www.newdomain.tld

This method is considered modern best practice because it is SEO friendly, preserves URL paths and query strings, works globally through Cloudflare’s edge network, and does not require any hosting server purely for redirects.

Why Cloudflare Redirect Rules Are Recommended​


Many older tutorials still rely on Page Rules, registrar forwarding, cPanel redirects, Apache .htaccess files, or NGINX configuration. While those methods still work, they are often harder to maintain and depend on a hosting server being online purely to perform redirects.

Cloudflare Redirect Rules are cleaner because the redirect happens directly at Cloudflare’s edge before traffic reaches any server. This reduces unnecessary hosting requirements and improves efficiency.

It also helps avoid common SEO problems caused by redirect chains and inconsistent domain handling.

For example, this is considered poor practice:

Code:
http://olddomain.tld
→ https://olddomain.tld
→ https://www.olddomain.tld
→ https://www.newdomain.tld

A direct redirect is much better:

Code:
http://olddomain.tld/about
→ https://www.newdomain.tld/about

This preserves SEO value properly and provides a cleaner experience for visitors.

Step 1 — Add DNS Records​


In Cloudflare, open the DNS section and create the following records:

Code:
Type: A
Name: @
IPv4 address: 192.0.2.1
Proxy status: Proxied (Orange Cloud)

Type: A
Name: www
IPv4 address: 192.0.2.1
Proxy status: Proxied (Orange Cloud)

The IP address itself is only a placeholder. Since Cloudflare handles the redirect before the request reaches any origin server, the actual destination IP does not matter.

The important part is ensuring the DNS records exist and are proxied through Cloudflare.

Step 2 — Create the Redirect Rule​


Open:

Code:
Cloudflare → Rules → Redirect Rules → Create Rule

Give the rule a name such as:

Code:
Forward to newdomain.tld

Under “If incoming requests match”, choose:

Code:
Custom filter expression

Then create the following conditions:

Code:
Hostname equals olddomain.tld
OR
Hostname equals www.olddomain.tld

Cloudflare will automatically generate an expression similar to:

Code:
(http.host eq “olddomain.tld”) or (http.host eq “www.olddomain.tld”)

Step 3 — Configure the Redirect​


Under the redirect action settings, choose:

Code:
Type: Dynamic

For the destination URL, use:

Code:
concat(“https://www.newdomain.tld”, http.request.uri.path)

Then set:

Code:
Status code: 301 - Permanent Redirect

and enable:

Code:
Preserve query string

How This Works​


With this configuration, all of the following:

Code:
http://olddomain.tld
https://olddomain.tld
http://www.olddomain.tld
https://www.olddomain.tld

will redirect directly to:

Code:
https://www.newdomain.tld

while preserving paths and query strings.

Examples:

Code:
https://olddomain.tld/about
→ https://www.newdomain.tld/about

https://www.olddomain.tld/contact?ref=google
→ https://www.newdomain.tld/contact?ref=google

Why Dynamic Redirect Matters​


The dynamic redirect expression:

Code:
concat(“https://www.newdomain.tld”, http.request.uri.path)

ensures visitors land on the equivalent page at the new domain rather than always being redirected to the homepage.

Without this, all requests would redirect only to:

Code:
https://www.newdomain.tld

which can break backlinks, reduce SEO effectiveness, and create a poor user experience.

Final Thoughts​


This setup works extremely well for website migrations, rebranding projects, parked domains, business acquisitions, country-specific domains, and SEO consolidation.

Compared to older redirect methods, Cloudflare Redirect Rules provide a cleaner, faster, and more scalable solution while reducing dependency on traditional hosting infrastructure.
 
 Short URL:
Back
Top