Try any GetResponse Plan for free. No credit card required

How to redirect non-WWW URLs to WWW using Cloudflare

Here’s how to redirect the non-www URLs of your website to the www version using Cloudflare without touching your .htaccess file. Most of the websites are accessible using both, the non-www URLs and the www URLs. But usually,Ā people don’t prefer that in order to comply with the best SEO practices. This is because search engines consider URLs with and without ā€œwwwā€ as two different websites or duplicate content and this can lead to a penalty.

NOTE: This post applies only to people who are using Cloudflare as their content delivery network (CDN) and DNS manager aka Cloudflare users.

Step 1 –

Login to your Cloudflare account on which the website for which you want to set redirects is active.

Step 2 –

Click on the ‘Page Rules‘ tab in your Cloudflare dashboard. It should look something like this šŸ‘‰Cloudflare Pagerules

Step 3 –

Then click the ‘Create Page Rule‘ button. Set the page rule as ‘Forwarding URL‘. Now have a look at the screenshot below and replace ‘yourgroovywebsite.com’Ā with your own website’s domain name and extension.

redirect non-www to www urls settings for cloudflare

Step 4 –

Once you’ve replaced ‘yourgrrovywebsite.com’ with your domain name, hit ‘Save and Deploy‘. Make sure that you have set the forwarding type as 301 – Permanent Redirect. Also, set the OrderĀ (not seen in the pic but you will be given that option when adding the page rule if you’ve already set any page rules before this) as First.Ā This is the order in which your Page Rules will be triggered. Only one Page Rule will trigger per URL, so put we must put thisĀ page rule at the top.

Step 5 –

We are nearly done but just to clear the previous settings,Ā purge your cache (though it’s not absolutely necessary) from your Cloudflare dashboard. To test if it is working properly, clear the saved files and cache from your browser and then try visiting the non-www URL of your website from the address bar and you will find it automatically getting redirected to the www version by default.

That’s it. Now all requests to the non-www version of your site will be getting redirected automatically to the www version. Rest is handled by Cloudflare.

If you still insist on creating the redirection with the help of .htaccess file, then follow this tutorial by SiteGround.

Caution: Download a backup of your .htaccess file before making any changes to it. Any misconfiguration in the .htaccess file can lead your whole website to crash!

Also Read: How to Serve Compressed Emoji in WordPress.

24 thoughts on “How to redirect non-WWW URLs to WWW using Cloudflare”

  1. Pro tip: Instead of making the forwarding destination ‘https://www.example.com’, make it ‘https://www.example.com/$1’. That way visits to ‘https://example.com/blost-post/3’ will take you to ‘https://www.example.com/blost-post/3’ instead of ”https://www.example.com/”

    Cheers

    Reply
    • Wait for the page rule settings to propagate across Cloudflare’s servers. Also, you can try clearing your browser’s cache in addition to Cloudflare’s own cache files and then try again. Hope you are able to get it fixed.

      Reply
  2. Thank you so much for this. I struggled for hours trying to do what could be done in 5 minutes with the right information.

    Reply

Leave a Comment