Cloudflare: How to redirect www to non-www domains

cloudflare-logo
  • Post author:
  • Reading time:5 mins read
  • Post category:WordPress
Rank Math SEO Plugin - Banner

This tutorial will show you how to redirect all traffic from your www domain to your non-www domain using a Cloudflare rule. You can set this rule with a free account (up to 3 rules). To redirect your traffic, and therefore optimize the SEO as well as the display speed of your website, you just have to follow these 2 steps: add a Cloudflare rule, then add a DNS record.

I Adding a rule

1. In your Cloudflare account, select your website.

Cloudflare Account Select Website

2. Select “Rules” from the sidebar.

Cloudflare Account Sidebar

3. Click the “Create Page Rule” button.

Cloudflare Account Create Page Rule

– In the first field just above the mention “if the URL matches”, enter the URL of your current website with the www, such as: www.mydomain.com/*. The asterisk will allow us to match the routes in the destination URL.

Cloudflare Forward url rule

– Select “Forwarding URL” and “301 – Permanent Redirection”.

– Destination URL: enter the URL of your website without the www, such as: https://mydomain.com/$1. The asterisk combined with the “$1” will match and retain all routes.

II Adding a DNS record

1. Select “DNS” from the sidebar.

Cloudflare Sidebar DNS

2. Click on the “Add record” button.

Cloudflare Add Record

In the “Type” field: choose “A”.

In the “Name” field, type “www”.

In the “Ipv4” field: enter your IP address (the same as the other DNS records).

Cloudfalre-A-Record-DNS

Recap in this video from the Cloudflare community:

Other SEO and Optimization articles.

Rank Math SEO Plugin - Banner

Article also available in : Français Español Deutsch Português Nederlands

Leave a Reply