How to setup free URL forwarding with Cloudflare (+ 301 wildcard redirects)

The woorkup.com blog used to be under the wpseer.com domain until I migrated it over a couple of years ago. I acquired wpseer.com and made the shift to a new name because this is not just a WordPress site, but targeted to many other types of marketers.

One issue I ran into was that while I had wpseer.com up, I had migrated it to HTTPS. So when I went to move to the woorkup.com domain, I had backlinks on both the HTTP and HTTPS versions. The problem was, I didn’t want to keep that WordPress site up and running just for the 301 redirects. And that is where Cloudflare came to the rescue with free URL forwarding.

Follow the tutorial below on how setup free URL forwarding with Cloudflare, along with 301 wildcard redirects. I’ve also included an alternative method you can do if your hosting provider supports it.

Free URL forwarding with Cloudflare

A while back I wrote a post about how to implement wildcard 301 URL forwarding with your domain registrar. However, the problem with that is, you can only do the HTTP version because doing URL forwarding from HTTPS requires having an SSL certificate installed.

The great news is, you can do this with Cloudflare, even if there is no hosting connected it. And what do I mean by a wildcard redirect? It means for example that any traffic that tries to access domain1.com/blog redirects to domain2.com/blog. So in this instance, the following 301 redirects work:

  • http://wpseer.com/ 301 redirects to https://woorkup.com
  • https://wpseer.com/ 301 redirects to https://woorkup.com
  • http://wpseer.com/* 301 redirects to https://woorkup.com/*
  • https://wpseer.com/* 301 redirects to https://woorkup.com/*

This ensures that all the backlinks on both the HTTP and HTTPS versions don’t break for SEO purposes. Remember, 301 redirects are needed to pass link juice. And this, of course, assumes that your URL structure remains the same on the new domain.

Step 1

First, you will need to add your domain that you want to redirect to Cloudflare. Simply signup for a free account and click on “+ Add Site.” The free plan works fine.

Cloudflare free plan
Cloudflare free plan

Step 2

Cloudflare will attempt to scan your domain for any existing DNS records. Simply delete everything it finds (unless you have email or something else you need).

You will want to add two dummy records. Basically you are going to point the domain to an IP address that doesn’t exist. This is because all you need is the URL forwarding to work. Add the following:

TypeNameValueTTLProxy status
A@192.0.2.0AutomaticOrange cloud
Awww192.0.2.0AutomaticOrange cloud

The 192.0.2.0 is an IP address that goes nowhere. Make sure you have the orange cloud enabled, as proxying to Cloudflare has to be on for the redirects to work.

Cloudflare DNS records

Once you’ve configured the DNS records click “Continue.”

Step 3

You will then need to point your current domain to the Cloudflare nameservers. You can do this at your domain registrar. Then click “Done, check nameservers.”

Cloudflare change nameservers
Cloudflare change nameservers

Step 4

Under the “SSL/TLS” menu, select “Flexible” SSL. You will need this to ensure that redirects over HTTPS also work.

Cloudflare Flexible SSL
Cloudflare Flexible SSL

This is because your origin server doesn’t support HTTPS, as it doesn’t exist. Remember, we are pointing to dummy IPs. Flexible SSL enables a universal SSL certificate on both *.domain.com and domain.com. This uses SNI and works on the following browsers:

Desktop Browsers installed on Windows Vista or OS X 10.6 or later:

  • Internet Explorer 7
  • Firefox 2
  • Opera 8 (with TLS 1.1 enabled)
  • Google Chrome v5.0.342.0
  • Safari 2.1

Mobile Browsers

  • Mobile Safari for iOS 4.0
  • Android 3.0 (Honeycomb) and later
  • Windows Phone 7

Step 5

Under the “Page Rules” menu click on “Create Page Rule.”

You will then want to enter the following pattern:

yourdomain.com/*

Select “Forwarding URL” and “301 – Permanent Redirect” for the settings, and input the following rule:

https://yourdomain.com/$1

The /$1 enables the wildcard part to function. Then click on “Save and Deploy.”

Cloudflare forwarding URL page rule

The single rule above makes the following work:

  • http://wpseer.com/ 301 redirects to https://woorkup.com
  • https://wpseer.com/ 301 redirects to https://woorkup.com
  • http://wpseer.com/* 301 redirects to https://woorkup.com/*
  • https://wpseer.com/* 301 redirects to https://woorkup.com/*

Read more about Cloudflare page rules. And that’s it! You can now ditch the hosting plan on your old domain and your wildcard 301 redirects will now be in place forever, pointing to your new domain. You can easily test different variations with httpstatus.

Tracking redirects with httpstatus tool
Tracking redirects with httpstatus tool

An alternative method with Kinsta

The whole point of the tutorial is that you don’t want to or can’t keep your old domain up forever just for the redirects. But you need to due to SEO, traffic, and old backlinks. If you’re using a hosting provider like Kinsta, you can also accomplish the same thing without taking up an extra site slot on your hosting plan. Here’s how.

Step 1

In your MyKinsta dashboard go to the domain that you are wanting to redirect or forward the old domain to. So in this example, I go to my woorkup.com site and add wpseer.com (old domain).

Add a domain to your existing site. Yes, many don’t realize you can actually add as many domains as you want onto existing sites. Make sure to keep the “Add domain with and without www” checked if you want to redirect both versions.

Add domain in MyKinsta dashboard
Add domain in MyKinsta dashboard

Step 2

Point the old domain to Kinsta’s servers if you haven’t already, and give it a little time to propagate. You can check it with a tool like whatsmydns.

Step 3

Then go to “Tools” and under “SSL certificate” click on “Update Let’s Encrypt certificate.”

Update Let's Encrypt certificate
Update Let’s Encrypt certificate

You will want to generate a certificate for the old domain (wpseer.com). This is important because it enables you to add redirects for HTTPS versions of the old domain, even though the domain isn’t technically hosted anywhere.

Generate free SSL certificate
Generate free SSL certificate

Step 4

Then go to “Redirects” and add a wildcard redirect. Choose your old domain, which is now available since you added it to your site.

Add 301 redirect at Kinsta
Add 301 redirect at Kinsta

Your “Redirect from” would the following:

/*

And then you want to redirect it to your new domain:

https://yourdomain.com/$1

And that’s it. Now your old domain has a wildcard 301 redirect over to your new domain.

Summary

Hopefully, this tutorial on how to set up free URL forwarding and redirects will help you on your next migration or domain name change. If you have any questions, feel free to drop them below in the comments.

5
Brian Jackson

I craft actionable content and develop performance-driven WordPress plugins. Connect on Twitter or subscribe to my newsletter (twice a month, no spam).

13 thoughts on “How to setup free URL forwarding with Cloudflare (+ 301 wildcard redirects)”

  1. Thankyou. But I think redirect check only work in httpstatus io. I have check at redirect-checker org doesnt work. Can you explain that? Thanks

    Reply
    • Hey Adjie,
      I would have to see it, so I’m not sure. However, I replaced HTTP Status tool above with Redirect Tracker. No ads :)

      Reply
  2. just wanted to tell you thank you,

    i just did a 301 and yeah i was facing the same problem. cloudflare was redirecting all the domains to home page but with $1 it redirected to the relevant pages.

    Reply

Leave a Comment

5