Configuring Cloudflare to Redirect WWW to Apex Domain

  •  1 min read

Congratulations! You are setup and using cloudflare for your DNS. Now is a good time to ensure that if people who are typing in your domain can actually get to your site.

Some people are in the habit of typing www in front of the domain name even though the www is not actually being used. To make sure your users are reaching your site with an error, we need to setup a redirect.

Fortunately, this is straight-forward and only takes a minute to setup.

Step 1

Log into your cloudflare account. In the left navigation at the bottom you will see a bulk redirects menu item. Click that and you will be presented with a screen similar to this.

bulk_redirects-step-1

This is what it will look like when we are done. For now, let's get startedy by clicking the Create Bulk Redirect List button.

Step 2

We want to provide a useful name. I have chosen to call this domain_redirects.

bulk_redirects-step-2

After entering the name, click the Next button.

Step 3

You could now upload a list of redirects, but this is beyond the purpose of this article. Instead click the link to maually add URL redirects.

bulk_redirects-step-3

Step 4

Enter the source URL. The format here is www.yourdomain.com/ ... The slash is important because webserver rules see a "/" as a directory, so this rule will catch everything from the root of the site "/" . In the target, specify your website, https://yourdomain.com. The status of 301 is what we want.

bulk_redirects-step-4

Then expand the edit parameters option and ensure the following items are selected:

  • Preserve query string

  • Subpath matching

  • Preserve path suffix

Then click Next.

Step 5

Confirm your details are correct and click Next.

bulk_redirects-step-5

Step 6

Now we need to create a rule to which we will apply this list. Click the Continue to Redirect Rules button.

bulk_redirects-step-6

Step 7

We need to provide a name, and I recommend www to apex as the name as this makes it easy to remember the purpose of the rule. The domain_redirects list we created will be selected as it is likely the only list you have.

bulk_redirects-step-7

Click the Save and Deploy button and that's it. We are done. You can now test that your redirect is properly configured.

For more information you can always refer to the cloudflare documentation for bulk redirects.

Profile picture of Jim Scott
Jim Scott

Jim is a seasoned technology executive with over 25 years of experience driving innovation in data-intensive industries. Prior to becoming CEO of Leed, Jim was the Head of Developer Relations for Data Science at NVIDIA, where he built the data science program to help empower developers to leverage the company's cutting-edge technologies in the fields of AI and data science. Previously, as Vice President of Enterprise Technologies at MapR Technologies, Jim provided architecture leadership across the company to support the business go-to-market activities. Jim has built systems scaling to 50+ billion transactions per day, and his work with high-throughput computing at Dow Chemical was a precursor to more standardized big data concepts. Jim is passionate about solving the largest and most complex business problems requiring deep subject matter expertise. . He has been featured in top publications like O’Reilly and Database Trends and Applications. Jim holds a BS in Computer Science, and an MBA.

© 2024 Leed. All rights reserved.