skip to content
Jonathan Dionne

Redirect Cloudflare Pages from wwww to non-www

/ 2 min read

You are using a custom domain on your Cloudflare Pages and you are looking for a way to redirect the traffic coming to your www subdomain to your non-www URL? You are at the right place!

Official documentation

The first thing I did was to look into the official documentation to look for an article describing how to achieve my goal. Sure you did too 😉.

I’ve found that article! I thought that would be it and straightforward but… unfortunately nah 🙄.

I can’t get my www.jonathandionne.com to redirect to jonathandionne.com and strangly I’m having success with any other subdomains I’m using but can’t get it to work for www 🤔.

Workaround: Page Rules

After some googling, I’ve found that answer (thanks cloonan) that suggest using Page Rules to achieve that goal.

  1. Visit the Cloudflare dashboard and select your domain.
  2. Click on the Page Rules tab.
  3. Click on Create Page Rule.
  4. In the If the URL matches field, input www.yourdomain.com/*.
  5. Select Forwarding URL and choose a 301 (Permanent Redirect) status.
  6. In the Enter destination URL field, input https://yourdomain.com/$1.
  7. Click Save and Deploy to create the rule.

Here’s an example of what I’ve done for my blog. Page Rules - Cloudflare Dashboard

The missing part

In a desperate attempt, I decided to try to add another custom domain on my Cloudflare Page, but this time I would add it with the www subdomain.

Custom domain - Cloudflare Dashboard Custom domain - Cloudflare Dashboard

I follow along with the next steps required to complete the setup and update my DNS settings with that new CNAME entry.

The last thing to do was to use one of the two methods described previously I chose the recommended one with Bulk Redirect List and Rule.

It worked! All traffic coming to my www subdomain is now redirected to my non-www domain 🎉.