How to 301 Redirect www to non-www in Cloudflare

"This Post contains affiliate links; this means we earn commissions if you shop through the links on this page"

301 redirect www to non www - Cloudflare - featured image

If you’re looking for an easier way to permanent 301 redirect www to non-www URL version in your Cloudflare account, here is the step-by-step process.

You won’t find complicated theory here. This is not more than three clicks to get it right.

And you’re done.

This process does not involve adding code to htaccess files or accessing your website files through an FTP program. It is a simple three clicks step to fix how I redirect www to non-www URLs.

But it will only work if you’re using a Cloudflare domain name server with your web host and want to redirect Cloudflare www to non-www URLs.

Before we dive into the actual steps, we must explore the differences between the www URL prefix vs non-www.

Should you prefer one over the other? The pros and cons, and which one should you set as the preferred domain URL version?

If one URL version is at all beneficial over the other.

A bit of Background History

At the earliest stage of the internet, when www was a massive thing, people often type www at the start of a website address.

The www (world wide web) letters were synonymous with the internet.

When you hear people say www, you’d think they’re talking about the entire internet.

I was thinking like that, too 😜

As time goes on and more people are now familiar with the use of the internet, website users realize they don’t need the www prefix to reach a website.

So, they started typing website addresses without the www at the beginning.

Webmasters noticed this trend and think it’s best to set the non-www address as the preferred URL version of a website.

A new form of SEO issues begins.

For search engines like Google, not setting the preferred domain URL prefix will lead to duplicate content issues. This is because search engines crawlers see www.yourwebsites.com as a different domain from https://yourwebsite.com

To a search engine, these are two different domains entirely.

To fix this type of duplicate content issue in the search engines, you only need to specify which URL version is the preferred one.

And before that, you also need to verify all versions of your website URL in the Google search console property. So, Google and other search engines alike will understand that irrespective of the URL prefix, they’re all one domain.

More on setting your preferred or canonical URL down the post.

WWW vs. Non-WWW Which one is better for SEO?

For most website owners – small businesses and individuals – there is nothing to worry about the SEO benefits between www and non-www URLs.

It’s just a matter of personal preference and what users find comfortable. There are no significant SEO benefits to using one over the other.

The only rule is that you stick to one and be consistent with it. If you prefer the www prefix, stick with it and if the non-www is your choice, that’s fine.

However, there are slightly technical benefits that come with www over non-www. But this is to be considered if your website receives millions of page views daily.

For clarity and honesty, let’s take a brief look at these technical benefits of www over non-www web addresses.

Advantages of www over non-www URL version

As mentioned earlier, if your website received millions of daily hits you may benefit from using www as the URL prefix.

This is because it’s easier to direct traffic to other servers if one gets overwhelmed by an inflow of website traffic.

Also, the www URL allows you to use a cookie-free domain which helps in reducing the number of HTTPS requests to boost performance.

You can restrict cookies to the root domain or specific subdomains. This is good practice as it prevents the use of cookies on a static page.

To learn more about the pros of using www in your URL, here is a website dedicated to the subject.

Why Should You use non-www?

First, www is obsolete in the face of today’s web users. I can’t remember the last time I typed www before a web address.

Do you still type www before a website address?

It’s unnecessary to type www to reach a URL. The non-www URL version of a website is easier to type, remember and say across verbally.

Removing www from your web address brings more brand consistency across marketing channels. This is because you don’t have to remember what you need to type – just type your domain name with the extension and you’re good.

Moreso, if you never need to restrict cookies on your domain, you can opt for a non-www URL prefix. And if your website does not get millions of visits daily, you have no business thinking about www.

To learn more about why you should drop www from your website URL, read this comprehensive post.

Duplicate Content and WWW or Non-WWW URL

If the content on a different URL is the same, Google considers this as duplicate content.

To search engines, www.yoursite.com is different from https://yoursite.com so this causes duplicate content issues.

Before 2019, Google wants you to set the preferred URL version in the Google search console but that’s a thing of the past.

You no longer need to do that in the search console anymore. Google announced you can use one of these four methods to communicate which is your preferred or canonical index URL.

  • Submit a Site with the preferred URL Version
  • 301 redirect to preferred URL prefix
  • Use rel=”canonical” HTTPS header
  • Use rel=”canonical” link tag on HTLM Pages

The website URL version you specify will be the one Google will crawl and have in its indexed. Do not submit an XML sitemap for both www and non-www versions of your site as this will lead to duplicate content issues.

If you need a more advanced guide on setting the canonical URL for your website, read this help documentation on the Google website.

How to Redirect www to non-www URL in Cloudflare

The process described here only applies if your website is added to Cloudflare and uses the Cloudflare domain name server – DNS.

Log in to your Cloudflare account and click on the domain you want to 301 redirect www to non-www URL version, then follow the steps below.

Selecting a domain in Cloudflare

#1. Page Rules

In your Cloudflare account, click on Rules from the top navigational menu link. If you’re on the free plan, you have only three-page rules to use. You must use your option wisely.

On the next page, click on the “create page rule” button.

Setting up page rules in Cloudflare

#2. Set up 301 Redirect WWW to Non-WWW

This is where you set up the 301-redirect www to non-www in Cloudflare.

In the first input field, enter your website www URL version – www.yoursite.com (do not forget to add the asterisk at the front of your URL like in the image below.

URL Forwarding in Cloudflare to set up 301 redirect

Select forwarding URL from the drop-down menu, and 301 permanent redirects from the second drop-down menu.

Next, enter your naked URL – https://yoursite.com – in the “enter destination URL” field. Note: add the $1 symbol in front just the way it is in the image below.

Setting the 301 redirect in Cloudflare

The next thing is to click on the “Save and Deploy” button. That’s it, from now every traffic to www.yoursite.com will redirect to https://yoursite.com.

Conclusion…

While www is out of fashion, it does have some slight technical advantages you might want to consider if you’re a large website.

For most websites, doing away with www will bring more benefits, help with branding, and improve user experience.

Also, it’s more convenient to type without the www prefix into the address bar. But whatever your URL version of choice, there is only one rule:

Pick one URL version, redirect the other to it, and stick with it. It does not help to change your domain canonical URL after setting one as the preferred version.

4 thoughts on “How to 301 Redirect www to non-www in Cloudflare”

  1. Hi Shamsudeen,

    It was a great share! My friend has recently set up a website. I think 301 redirects are a common problem, and people often don’t know how to correct it. I have a friend who uses Cloudflare and since he is new to using it, he does not know much about all this. I think this article will help a lot of people. I really loved how you covered all the important aspects of this article. It will definitely help him, and several people like him who are new website owners.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.