How to configure www subdomain to redirect to and serve Pages content
Hello all. I have spent several hours trying multiple permutations of the settings I think should work, but haven't been successful. I am hoping that someone on here can help me.
DESCRIPTION AND WHAT'S CURRENTLY WORKING I have a new domain fully activated on cloudflare, a cloudflare pages project successfully built and deployed to a pages.dev URL, and a DNS cname record pointing from my Apex domain to mypages.dev URL through a proxy.
This all works correct and the apex domain is correctly serving content as I would expect.
CURRENT PROBLEM AND WHAT I'VE TRIED I now want the www subdomain URL to redirect to the apex domain URL and serve the same pages.dev content. i.e., I type https://www.example.com/ into the browser address bar, I get a 301 redirect to https://example.com/ and my pages project renders
I have: 1. added a cname DNS record for the www subdomain and pointed it at the pages.dev URL, also proxied. 2. Added a bulk redirect rule so that the www subdomain redirect to the Apex domain with a 301 permanent status. 3. And I have tried adding and removing the www. Subdomain to my cloudflare pages project' Custom Domains list. Neither configuration works.
When I add my www subdomain as a pages custom domain, then the subdomain URL does resolve correctly... But it doesn't get redirected. And in that scenario I'm basically serving the same pages.dev content on both the Apex domain and the sept domain... Which I don't want because that's not canonical and can lead to confused SEO.
And when I remove the subdomain as a pages custom domain, I receive a 522 connection timed out response.
If I don't add a cname record for the subdomain, then DNS doesn't even know what to do with the www URL.
Any help or advice would be greatly appreciated. Thanks!