Redirecting a Site With CloudFlare
Changing a domain name can have negative consequences on your business, no matter how good your intentions might be. Potential impacts include loss of SEO value, loss of customers and web traffic, and loss of brand awareness.
For all these reasons, when my dear friends at Create Cooking School recently made the decision to change their domain name, we first had to weigh the benefits with the potential impacts listed above. Their reasons for wanting to change the domain name were perfectly reasonable.
First, they had received feedback from some customers that the domain name was too long. This wasn’t so much a problem for web traffic, but for people sending e-mails it meant having to type along domain name, which meant there was a potential for typos. Second, they wanted to change the domain name to align with their registered business name.
Luckily they were in somewhat of a unique position with their business. They were building a brick and mortar store and had not opened yet. Although they had been advertising on social media, they were still relatively unknown. Additionally, the website was not receiving much traffic while the business was waiting to open.
All of this meant that changing the domain name was not as risky as it would normally be for an established business. But it still had to be done properly.
In this article I’ll discuss how I used CloudFlare to handle redirecting traffic from the old domain to the new one.
The Benefits of CloudFlare Redirection
While there are a number of ways to redirect from one site to another, I like CloudFlare for several reasons.
First and foremost, it’s incredibly simple. As we’ll see below, redirecting one site to another is just a few simple clicks with CloudFlare. A single rule can redirect an entire domain to another. Conversely, it’s easy to disable the redirection if you ever need to.
But the real reason I like using CloudFlare for redirecting is because you only need to host one web site instead of two. All of the alternative methods below require two active web site installs: the one you are redirecting to, as well as one to handle the redirection.
With CloudFlare, you only need one website: the one you are redirecting to. You do not need a second website because CloudFlare intercepts all of the requests and redirects traffic for you.
Of course there are two sides to every coin. CloudFlare is great, but it does have limits. First and foremost, the domain you are redirecting from must be under CloudFlare control. For example, if you want to redirect from domainA.com to domainB.com, domainA.com would need to be managed by CloudFlare.
The other potential limitation is if the URLs on the two sites are not identical. To do the redirects with CloudFlare, we utilize their page rules tool. By default, each domain can only have 3 page rules. This works great if all the URLs are the same across both websites. However, if the URLs are not the same you may need to purchase additional page rules from CloudFlare.
Redirecting a Site with CloudFlare
If you’ve read through the pros and cons of CloudFlare redirection above and decided it’s right for you, then keep reading. If you can’t use CloudFlare for your redirection, skip to the next section and I’ll show you some alternative methods.
To get started, login to CloudFlare and find the domain you are redirecting from. Again, this domain must be under CloudFlare control. The domain you are redirecting to does not have to be under CloudFlare control, however.
You should already have an A record for the domain you are redirecting from (otherwise the site wouldn’t load at all). Now you need to add another A record for the domain to you want to redirect to. From reading various support threads, the IP address of this entry apparently does not matter. It can be the same as your existing domain, the real IP of the new domain, or some bogus value.
Notice both of the cloud icons in the graphic above are orange. This indicates that web traffic, and not just DNS, is proxied through CloudFlare. In my experience, both icons must be orange for the redirect to work.
After the DNS changes are saved, click the Page Rules icon. Here is where we will create the redirect rule that tells CloudFlare to redirect requests from the old domain to the new one.
If every URL on the old site exists on the new site, a single page rule is all you need:
Here are what each field means:
- https://*createcookingschool.com/* – This is the pattern to match. The first * will handle both www and non-www requests. The second * matches any characters after the domain name.
- Forwarding URL – This is the action CloudFlare will take when the above pattern matches. There are lots of choices here but for redirection this is the one we want.
- 301 Permanent – There are 2 types of redirects: permanent and temporary. In HTTP speak, these are known as 301 and 302, respectively. For redirecting a domain, you’ll almost always want to use permanent.
- https://createfoods.co/$2 – The final field is the new domain we want to point to. The $2 will be replaced with whatever the second * from the above pattern matched.
If, on the other hand, the two domains have a different set of URLs, you will need multiple page rules. Just remember that you only get 3 page rules for free. And page rules are executed in order: the first rule that matches is executed, and then no further rules are checked. This means you should put your most specific rules first, followed by more generic (or wildcard rules) at the end.
Once you save your page rule(s), make sure they are active. You can deactivate/active any or all rules by simply toggling the green slider icon. In my experience page rules take effect immediately, but there could be some lag (hopefully not more than a minute or so).
If you’re familiar with the curl command, you can also verify the redirect is working that way:
$ curl -sI https://createcookingschool.com/
HTTP/1.1 200 Connection established
Date: Thu, 13 Sep 2018 13:03:34 GMT
HTTP/1.1 301 Moved Permanently
Date: Thu, 13 Sep 2018 13:03:34 GMT
Expires: Thu, 13 Sep 2018 14:03:34 GMT
The two lines we care about are HTTP/1.1 301 Moved Permanently and Location: https://createfoods.com/. Together these confirm the redirection is working as we expect.
And that’s all there is to it. You can verify everything is working by visiting the old domain in a web browser, and you should see the new domain displayed. If not, double check your page rules: a single mistyped character can cause the rule to fail.
Other Ways to Redirect Without CloudFlare
If CloudFlare is not an option for you, there are still plenty of ways to get one domain to redirect to another one.
If the site you’re redirecting from is WordPress, I highly recommend the Redirection Plugin. I have used this plugin on multiple site and it works great. The interface is easy to follow, and it lets you do much more than just redirects. For example, it lets you do forwarding, which has the same net result as a redirect except the browser never sees the redirect (it all happens on the server).
More generically, if the above plugin doesn’t work for you, or you don’t use WordPress, your other option for redirection creating redirect rules. I’ll show an example for Apache web server below, but nginx also offers its own redirect module.
The following rewrite rules handle a couple of specific URLs first, and then the last one is a wildcard that catches everything else. These should be placed in your server’s .htaccess file.
Redirect 301 /contact.php https://createfoods.co/contact
Redirect 301 /about-us https://createfoods.co/about
Redirect 301 /* https://createfoods.co/
Notice once again we’re using the 301 redirect type to indicate that this is a permanent change.
Redirecting one domain to another should not be done on a whim, but it also doesn’t have to be scary. I recommend using CloudFlare whenever possible, but if that’s not possible there are still plenty of other options that work across different platforms.
Regardless of which way you implement redirects, there is one more task you should perform: update Google search console. You’ll want to create a new property for the new domain and submit a sitemap file.
Additionally, if you use Google Analytics, I recommend generating a new tracking code so that you confirm no more traffic is visiting the old domain. You can reuse your existing tracking code, just make sure you update the domain name to match the new one you are using.