Webhosting

Bulk 301 Redirect Setup on Cloudflare

By June 5, 2023 No Comments

Cloudflare’s 301 Redirects: A Step-by-Step Guide to Seamlessly Transition Your Content

Setting up bulk 301 redirects in Cloudflare is a crucial task when moving from an old domain to a new one, or whenever you’ve restructured your site’s content. These redirects ensure that users and search engines are directed to the right content, maintaining the usability of the site and the SEO value of your pages.

In this post, I’ll walk you through the steps needed to set up 301 redirects in Cloudflare. Importantly, I’ll cover an often-overlooked trick that ensures your redirects work correctly: pointing your CNAME records to 192.0.2.1.

Getting Started with Cloudflare

Before we delve into the specifics of setting up 301 bulk redirects, make sure you have a Cloudflare account and your website is correctly set up in Cloudflare. If you are new to Cloudflare, you can create an account for free and follow the instructions to add your website.

Pointing your CNAME Records to 192.0.2.1

A key element of getting your 301 redirects to work correctly on Cloudflare involves configuring your CNAME records properly. While the typical approach is to point your CNAME records to your domain or subdomain, a trick to ensure that the 301 bulk redirect works correctly on Cloudflare is to point these CNAME records to 192.0.2.1.

This seemingly arbitrary IP address is known as a “TEST-NET” address in the documentation of Internet Engineering Task Force (IETF). It’s designated for documentation and example purposes, which means it’s reserved and not routable on the internet. By using this, you’re essentially creating a placeholder for your CNAME record.

Here are the steps to update your CNAME record:

  1. Log in to your Cloudflare account and choose the site you want to work on.
  2. Go to the DNS settings page.
  3. Click Add Record.
  4. Choose CNAME as the record type.
  5. Enter the name of your subdomain.
  6. In the Target field, enter 192.0.2.1.
  7. Set the TTL to Auto and set the proxy status to DNS Only.
  8. Click Save.

Please note, this change might take some time to propagate.

Setting up 301 Bulk Redirects

With your CNAME records correctly set, you can now proceed to set up your 301 bulk redirects. To do this, you’ll need to use Cloudflare’s Page Rules.

Here are the steps to follow:

  1. From your Cloudflare dashboard, select the appropriate domain.
  2. Navigate to the Page Rules section.
  3. Click Create Page Rule.
  4. In the field that appears, enter the URL pattern you want to redirect from. For example, if you’re redirecting from an old domain to a new one, your pattern might look like this: olddomain.com/*
  5. Next, you’ll see a dropdown labeled Then the settings are. Here, select Forwarding URL.
  6. In the next dropdown that appears, select 301 – Permanent Redirect.
  7. In the field labeled Enter destination URL, enter the URL you want to redirect to. If you’re redirecting to a new domain, your URL might look like this: newdomain.com/$1
  8. Finally, click Save and Deploy.

This will apply the rule immediately. Please note that $1 represents the first wildcard in your URL pattern, and this syntax can be expanded for more complex redirects. For instance, if you have a URL pattern like olddomain.com/*/posts/*,