How to redirect one Domain to Another with Cloudflare explained.

How to redirect one Domain to Another with Cloudflare explained.

Up until a few days ago, I did not know you can manage URL and domain redirects and forwarding directly in the Cloudflare dashboard. Other domain name registrars and web hosting companies can do this too (eg. name.com), but I did not know how to manage this in Cloudflare. Maybe you don’t know either and that is why this post exists. Let me show you.

Scenario

Let’s assume you want to redirect from old-domain.com to new-domain.com.

Step 1 — Update DNS Settings

First, make sure you manage the domain you want to redirect from on Cloudflare. Next thing you do is adding the following DNS settings:

Update DNS Settings

In this case, we redirect the root (@) and www of the domain. Point it to a dummy domain, in this case, 192.1.2.3 (got this from here). It’s important that you set the proxy status to Proxied.

Step 2 — Set up Page Rules

Finally, we add a redirect page rule. When you are not sure which status code fits, read “301 vs. 302 Redirects & SEO: The What, Why & How” on searchenginejournal.com.

In this example, every hit on the old domain (no matter if you open the site with or without www or with https or http) is redirected to the new one.

Set up Page Rules

What does this page rule do now? If the URL matches it will forward the browser to the new target. The following examples will be redirected:

  • old-domain.com => https://new-domain.com
  • www.old-domain.com => https://new-domain.com
  • old-domain.com/hello => https://new-domain.com/hello
  • www.old-domain.com/hello => https://new-domain.com/hello

That’s it. You successfully redirected a domain to another with Cloudflare. Congrats!