# 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](https://nttr.st/3rRIFLc). Other domain name registrars and web hosting companies can do this too (eg. [name.com](https://nttr.st/37880Z2)), 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1613196754644/3esLBigN9.png)

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](https://community.cloudflare.com/t/redirecting-one-domain-to-another/81960?ref=natterstefan.me)). It’s important that you set the proxy status to `Proxied`.

### Step 2 — Set up Page Rules

Finally, we add a redirect [page rule](https://support.cloudflare.com/hc/en-us/articles/218411427-Understanding-and-Configuring-Cloudflare-Page-Rules-Page-Rules-Tutorial-). When you are not sure which status code fits, read [“301 vs. 302 Redirects & SEO: The What, Why & How”](https://www.searchenginejournal.com/301-vs-302-redirects-seo/299843/) 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1613196775068/YriXho04_.png)

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!
