DEV Community

Tiny
Tiny

Posted on • Originally published at tinygame.dev on

Custom Cloudflare domain and www redirect

Why doesn't www work for my domain?

Cloudflare can serve as an excellent static site host, I use it for my 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.

  1. In your Cloudflare dashboard, go to Websites > your website > DNS. Add a new CNAME entry with the name www and mysite.com as target, and make sure you turn on the proxy.
  2. Go to Rules > Page Rules and set up a new redirect rule. Set the URL to www.mysite.com/*, pick the Forwarding URL setting, and the 301 status code. Set the destination URL to https://mysite.com/$1.

And we're done, www should now redirect to you domain as expected.

Top comments (0)