How to redirect www to non www traffic on Cloudflare

Endrit Qerreti

Endrit Qerreti

In this tutorial you will learn how to redirect www traffic to non www with Cloudflare page rules. By using this method you can redirect www traffic to non www traffic without changing anything on your web server.

Step 1 - Setup DNS

Before you create the page rule you need to make sure you have a www record on your dns as page rules work only when the www dns is proxied through cloudflare

If you don't have one, create it by clicking the "Add record" button

Next, select Type: A Name:WWW IPv4:Ip-address and click the save button.

In this setup we are using a cloudflare IP because this record will only be used to redirect the www traffic. You can use your server IP aswell as this is just an example.

Step 2 - Create Page Rule

Cloudflare page rules lets you do a lot of things, in this tutorial we are using page rules to setup a 301 redirect of www traffic to our site without www.

Click to Rules and go to Page Rules

Next, click Create Page Rule button

Now on this section you need to add

1) Set url to* as shown in the image below, the asterisk means that the www url will be redirected to the same path that was requested under www

2)Click the drop down box and select "Forwarding URL"

3) Select "301 - Permanent" on status code box

4)Set destination URL to$1

5) Save and Deploy page rule

6) That's it!

How to Activate / Deactivate Page Rule

Turning ON/OFF your page rules is only click away, simply go to Page Rules sections and click the switch button as show on the image below.

The switch button has two states, green and gray

Green - The page rule is active

Gray - The page rule is not active

How to Edit Page Rule

To edit the page rule, click the settings icon as show in the image below

How to delete Page Rule

Page rules can be deleted by clicking the X button


In this tutorial you learned how to setup a page rule on cloudflare that allows you to create a 301 permanent redirect.