Cloudflare domain forwarding when switching domain name

Sam Domain & Email Solutions

Domain name providers like Godaddy allow you to easily forward your domains. However if you use cloudflare you can accomplish the same thing just with an extra step using page rules.

If you use the basic URL redirect for the whole domain like olddomain.com, then you lose anything else in the URL like the specific page a user was trying to visit such as olddomain.com/about-us

So if you set up the page rule pattern:

olddomain.com

And set it to forward to:

newdomain.com

Then if someone entered:

olddomain.com/about-us

They would be redirected to:

newdomain.com

Instead of:

newdomain.com/about-us

Here is the page rule pattern to use in Cloudflare so that the information after the .com is kept:

Set the URL Matches field to the old domain and add a * before the domain and /* after the domain name:

*olddomain.com/*

Then select the settings Forwarding URL and 301 – Permanent Redirect and input the new URL in the field below and add /$2 to the forwarded URL:

https://newdomain.com/$2

Save the rule. Now if someone visits:

https://www.olddomain.com/about-us
Or
http://olddomain.com/about-us

They will be redirected to:

https:newdomain.com/about-us

If you are permanently changing your domain name, set the following DNS records:

Change or create an A record with name: @ and the ipv4 value to 192.0.2.1 which is a dead end so that search engines better detect the 301 Redirect.

Change or create a second A record with name: www and the ipv4 value to 192.0.2.1 as well.

This will help you keep your customers happy, help with SEO and make the domain change seamless.

If you use Google Search Console, you can then tell Google about the domain switch via Search Console settings to help with SEO.