How to redirect your site to a new domain using Cloudflare

Failing to properly redirect your website to a new domain can result in loss in SERP rankings, drop in traffic, and drop in domain authority.

This guide will show you exactly how to use Cloudflare to redirect your website from domain A to domain B using a 301 (permanent) redirect.

You’ll find this guide useful if:

  • You’ve move your site to a new domain and want to avoid losing domain authority in Google and other search engines.
  • You’ve merged two pieces of content and want to make sure the outdated URL resolve to the correct page.
  • You’ve removed and outdated piece of content and want to send users to a new page.

Overview of redirect types

There are several types of redirects. They depend on how long you expect the redirect will be in place and what page you want to show up in search engines:

  • Temporary redirects for during website maintenance or downtime.
  • Permanent redirects to preserve existing links, keep (Meta) Ads running without losing historical data, etc.

Technical methods used to implement redirects

While users generally won’t be able to tell the difference between different implementations, choosing the optimal method is important when it comes to SEO and a seamless user experience:

  • HTTP Redirects: Implemented on the server-level.
  • Meta Refresh Redirects: A HTML tag-based redirect.
  • JavaScript Redirects: Executed on the client side using JavaScript.
  • Frame Redirects: Used to display contents of website B on domain A.
  • PHP or Server-Side Scripting Redirects: Implemented using server-side scripting languages like PHP.
  • DNS Redirects: Done at the Domain Name System-level.
  • Proxy Redirects: Using a proxy server to redirect requests.

Why use Cloudflare to redirect your site?

The redirect we’ll be implementing is handled on the network edge (close to the user), where Cloudflare responds with an HTTP redirect status code (like 301 or 302).

This means the request will be redirected before it ever reaches the origin server and will therefore a) reduce the load on our server and b) be a lot faster.

The process

Let’s get started.

In this example, I’ll be redirecting old.alazanski.com, including its URLs, to alazanski.com. In other words, we want to redirect the request for old.alazanski.com/blog to alazanski.com/blog and not to alazanski.com.

First, make sure you’ve added your domain to Cloudflare.

Next, make sure the DNS records of the (sub)domain you want to redirect are proxied. If you want to redirect your domain with and withou “www”, both DNS records should be proxied.

I’ve added the subdomain “old”, set it to Google’s free public DNS (the IP address is totally arbitrary) the subdomain old, and set it to “Proxied”.

Adding a proxied record to Cloudflare

Next, go to “Rules”, then “Redirect Rules” and click “Create rule”.

This is where the magic happens.

Give your redirect rule a descriptive name, like “Old to root domain redirect”.

Select “Custom filter expression”.

Select Hostname in the Field dropdown menu, Equals (Operator), and enter your domain name in the Value field.

In the URL redirect section, choose the Dynamic Type.

Redirect your domain using a concat expression

Enter the following expression in the Expression field and replace “https://alazanski.com” with your desired destination URL):

concat("https://alazanski.com", http.request.uri.path)

What this expression does is it builds the destination URL using the static domain “https://alazanski.com” and the user’s requested URI path and then redirects the user to said URL.

So a request made to https://old.alazanski.com/folder1/folder2/ would resolve to https://alazanski.com/folder1/folder2/.

If your redirect is permanent, select the Status code “301”.

If you’d like to preserve the query string in the redirect (such as UTM parameters), make sure to check the “Preserve query string” box.

Click “Deploy” to save your new rule.

And that’s it. You’ve successfully redirected your old domain to a new domain using a 301 redirect.

Categories SEO