Magazine

How to 301 Redirect Www to Non-www in Cloudflare

Posted on the 09 February 2022 by Shamsudeen Adeshokan @cybernaira

If you're looking for an easier way to permanently 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.

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 URL version of your site?

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 URL prefix will lead to duplicate content issues. This is because search engines crawlers see www.yourwebsites.com has 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 search console. 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 with. 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 typing 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 not the same as https://yoursite.com so this causes duplicate content issues.

Before 2019, Google wants you to set the preferred URL version in the 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 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

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 redirects www to non-www URL version the follow the steps below.

#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.

#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.

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.

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.


Back to Featured Articles on Logo Paperblog