Custom Cloudflare domain and www redirect
Why doesn’t www work for my domain?
Cloudflare can serve as an excellent static site host, we use it for this blog. It’s also simple to register a custom domain and have it auto-setup, but unfortunately the www subdomain doesn’t automatically redirect as expected. By default https://mysite.com
will work, but www.mysite.com
won’t. Here’s how we fix it.
- In your Cloudflare dashboard, go to Websites > your website > DNS. Add a new CNAME entry with the name
www
andmysite.com
as target, and make sure you turn on the proxy. - Go to Rules > Page Rules and set up a new redirect rule. Set the URL to
www.mysite.com/*
, pick theForwarding URL
setting, and the301
status code. Set the destination URL tohttps://mysite.com/$1
.
And we’re done, www should now redirect to you domain as expected.