301 Redirect www to non-www from Cloudflare

Have you checked if your website is accessible through both www.yoursite.com and yoursite.com URLs?

Because if your website is accessible through the both www and non-www, this might grow into a serious SEO problem over time.

But… you can quickly resolve this by using Cloudflare’s Page Rules option. Please note that this will only work if your website is added to Cloudflare.

Here’s how to do it:

Cloudflare www to non-www redirect

#1 – Open Page Rules in Cloudflare

First of all, log into your Cloudflare dashboard and select the website that you want to add the 301 redirect for.

Now, go to the Rules section and click on the Create Page Rule button as shown in the screenshot below:

Add Page Rules - Cloudflare

#2 – Add 301 redirect rules

Now, it’s time to add the actual 301 redirect rules that will send all your www traffic to the non-www (or, naked) version of your website.

Edit Cloudflare Page Rules
  1. Add www.yoursite.com/* in the first field
  2. Select Forwarding URL in the first dropdown field
  3. Select 301 – Permanent Redirect in the second dropdown field, and
  4. Enter https://yoursite.com/$1 in the last field

If your website is http then use http instead of https in the 4th step above.

That’s it, all the www requests should now be redirected to the non-www version within a minute.

Please note that the page rules only work if you have Proxy Status turned on for A and CNAME records in the Cloudflare DNS section.

If you’re stuck somewhere, please let me know by dropping a quick comment below.

Similar Posts

Leave a Reply

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