How to setup DNS to fwd root domain to www?

Hello expert,

How do we setup DNS in Cloudflare to forward root domain to www?

For example, how to forward mysite(.)com to www(.)mysite(.)com

Is below setup correct?

Type: Cname
Name: @
Target: www(.)mysite(.)com

As far as DNS alone is concerned, that is correct.

But I’d really suggest to use the search :wink:#tutorial

1 Like

A CNAME is not a redirect.

A CNAME creates an alias for a canonical name. In your record example.com (referenced by @) is the alias for the canonical name of www.example.com. Normally a CNAME at the apex of a domain is problematic due to no other records being permitted to exist in the same space as any other record types (DNSSEC records being an exception).

Thanks to Cloudflare employing CNAME flattening which synthesizes A and AAAA records, you are able to avoid the usual problems caused by creating a CNAME at the apex.

HTTP hostname headers is where the part about a CNAME not being a redirect becomes particularly relevant. Requests sent to example.com will arrive at the same web server as requests for www.example.com. The request will still be asking for example.com. What happens next depends on how the origin web server is configured handle requests for example.com. If it has no configuration, you may arrive at the server’s default site. If the apex name has been configured as an alias for the www site, you will see its content, but it will appear as a duplicate site to search engines.

You will be better served by an actual HTTP redirect which will cause requests for example.com' to automatically make a new request to www.example.com. Page rules used to be the only way to achieve that without creating the redirect on your origin server. Cloudflare’s new bulk redirects now offers another effective method of achieving the same.

2 Likes

From a DNS point of view, the OP’s setup is absolutely correct, though. And that was the OP’s question. That this is not enough for an HTTP redirect is a different story of course and that’s where @domjh’s lovely tutorials come in, which can be easily discovered with the search.

3 Likes

Thanks for guidance.

1 Like

You are genius. Thanks for your kind tips.

1 Like