Ben Borgers

How to redirect www subdomain with Cloudflare

January 23, 2022

You can easily redirect a www subdomain with Cloudflare (like redirecting www.example.com to example.com).

First, weā€™ll create a dummy record in Cloudflare for the www subdomain, so that Cloudflare can control it.

Create an A record for the www subdomain of your domain, with the IP address 192.0.2.1. This IP address doesnā€™t actually matter; what matters is that Proxied is turned on. This way, Cloudflare sits in front of your www subdomain, and we can redirect it using Cloudflare.

Next, go to Page Rules for your domain in Cloudflareā€™s settings.

Create a rule for your www subdomain (for example, if my domain was example.com, Iā€™d do www.example.com). Set the settings to ā€œForwarding URLā€ with a 301 redirect to https://example.com/$1 (again, replace example.com with your domain).

Save this page rule. Now, your www subdomain will redirect to the corresponding page on your non-www (ā€œnakedā€) domain!

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗