Cloudflare Redirects: How to Setup 301 Redirects (URL Forwarding) Using CloudFlare’s DNS & Page Rules

Devin Schumacher
5 min readMar 24, 2024

You recently set up a new domain on CloudFlare and are worried that people who saved the old URL might not be able to find the new one. You have a really popular article about “how to poop standing up” 💩.

It appears that certain 301 redirects need to be set up!

Unfortunately, setting up a 301 redirect using CloudFlare is not that simple.

Since nobody likes to read paperwork, I reasoned, a true hero should take the initiative and lessen the load on the rest of the world.

Once again, I am the internet hero coming to make your life easy. You can download and use the SOP, the video, and the material I have available at a later time.

✔️ https://devin.to/ps-cloudflare-redirects is the checklist/SOP

TOC

Cloudflare Backlinks: How to Setup 301 Redirects (URL Forwarding) Using CloudFlare’s DNS & Page Rules

How to setup a CloudFlare 301 redirect using “page rules”

  • 1. Add Domain to CloudFlare
  • 2. Update NameServers
  • 3. Update CloudFlare DNS
  • 4. Setup Page Rules for URL Forwarding
  • 🎁 Free Gifts

How to setup a CloudFlare 301 redirect using “page rules”:

The process of setting up redirects using Cloudflare’s DNS is pretty simple. You add your domain, point the CloudFlare DNS records (A record & CNAME record) to Cloudflare’s server, and then setup a URL forwarding rule. That’s pretty much it.

The first two steps of this walkthrough have nothing to do with the actual CloudFlare 301 setup. They are the things you need to do before any of this works. So, if you’ve already added your domain to your CF account and pointed your domain registrar’s nameservers to it — you can skip them and start at Step 3.

1. Add Domain to CloudFlare

At the dashboard (dash.cloudflare.com) of your CloudFlare account click the “Add a site” button, and enter your domain on the next screen.

Once you do that, you’ll be presented with pricing options. Just choose the free one (bottom of screen) and move on.

Cloudflare will scan for existing DNS records and bring them over.

You can choose to keep them or remove them, depending on what you’re attempting to accomplish.

Once you click “continue,” the nameservers for your account will appear.

The nameservers for your current domain must be updated. You can discover them at the domain registrar, which is also typically where you bought it and where you log in to view your domain.

2. Update NameServers

There are literally a trillion web hosting companies out there, therefore I can’t create a lesson on how to update DNS at every one of them.

All you have to do is login to your account, select your domain, click “edit nameservers” or a similar option, and then enter the nameservers that Cloudflare provided you with in the previous step.

Now, it could take ten minutes to forty-eight hours for those modifications to become operative. We refer to this as propagation.

However, you don’t have to hold off till it happens. But for whatever you do after work, you’ll have to wait for it.

3. Update CloudFlare DNS

This is where the actual process starts.

Go to your domain settings in CloudFlare and choose “DNS”.

I normally start by erasing the DNS records that CloudFlare has migrated over if I’m redirecting the entire domain. If you have important records in there, don’t do that.

Yeah, I am aware of the obvious captain, but Under these intensely stressful IT environments, common sense isn’t often that common.

The CloudFlare DNS records that are required for your URL forwarding to function will then be added.

After adding the following data, click “Add record” and then “Save”:

  • Type: A
  • Name: @
  • IPv4 Address: 192.0.2.1

Now, click the ‘Add record’ button again, add the following information, and click the ‘Save’ button:

  • Type: CNAME
  • Name: www
  • Target: @

4. Setup Page Rules for URL Forwarding

Navigate to the “Rules” area on the sidebar, then click “Page Rules” and click the ‘Create Page Rule` button.

Now it’s time to set your 301s!

I’m going to setup a 301 redirect to forward all traffic coming to ‘domain A’ to ‘domain B’, but you can easily just change the URL & destination to fit your needs.

Follow these steps:

  1. Enter the URL pattern you want 301ing
  2. Click the dropdown and choose ‘URL Forwarding’
  3. Select your ‘Status Code’ from the drop down (probably 301)
  4. Enter the destination
  5. Click ‘Save and Deploy Page Rule’

I typed the root domain and included an asterisk (*) to indicate that it will also redirect users that visit an inner URL, such as “domain.com/whatever-asdfadf.”

Additionally, you can build up inner URL-specific 301s.

I’m just going to repeat the identical action now, but with the addition of the www. version.

Same steps from above:

  1. Enter the URL pattern you want 301ing
  2. Click the dropdown and choose ‘URL Forwarding’
  3. Select your ‘Status Code’ from the drop down (probably 301)
  4. Enter the destination
  5. Click ‘Save and Deploy Page Rule’

And that’s it! You’re through!

You ought to be able to access the destination by going to your redirected domain.

If it is unsuccessful, confirm:

  1. You’ve let your nameservers ample time to spread (see to step #2).
  2. If you moved your domain from another Cloudflare account, you must clear the CloudFlare cache.
  3. You can try using “incognito mode,” which opens an incognito window by pressing shift + command + n on most Mac browsers, or clearing the cache on your browser.

Free Gifts

Get the free How to setup a Cloudflare 301 Redirect checklist, and run it anytime you need to repeat this process.

Resources:

--

--