My web-app works when visited without a www prefixed to its domain, but it returns a 522 error when visited with a www prefix

I am hosting a simple web-app on Cloudflare using pages and a basic DNS configuration for a custom domain name. For privacy sake, call it myapp. When I visit https://myapp.com the web-app works correctly, but when I visit https://www.myapp.com I am shown a 522 error.

I have subdomain set up and working correctly, admin.myapp.com, using the following DNS record:

type: CNAME, name: admin, target: myapp-admin.pages.dev

I have tried doing the same for a www subdomain to no success, using the following DNS record:

type: CNAME, name: www, target: myapp.pages.dev

My custom domain maps to my Cloudflare pages domain using this DNS record:

type: CNAME, name: myapp.com, target: myapp.pages.dev

Where might I be going wrong here?


Solution 1:

Solved by creating a page rule that enables forwarding/redirects.