Using CNAME to redirect subdomains to main domain

I am trying to set up my DNS records so that all subdomains redirect to my maindomain, for example:

blog.example.comwww.example.com
foo.example.comwww.example.com

I have setup a CNAME record as follows:

But this does not work. Nor does setting simply example.com as the target. Any help much appreciated.

Heyo,

Cnames don’t work like redirects unless you’ve setup something on your webserver, to redirect everything to your main domain you can use a page rule.

You just need to create the following

DNS AAAA record pointing to 100::

Then in page rules create the following

URL = *.example.com
Pick a Setting = Forwarding URL
Destination URL = example.com

Order = First

Let me know if you need any more help:slight_smile:

What do you mean by “DNS AAAA record pointing to 100::”? What do I put in the target and name sections? And would I have to create something similar for A records for IPv4? Thanks


All you need is something like this purely to have the catch all option, Cloudflare automatically adds an A record behind the scenes doing the same thing :slight_smile:

1 Like

Perfect, thank you. Out of curiosity, how come this method still didn’t work even when I specified a specific, rather than a wildcard, subdomain, like this for example:

Since a Cname doesn’t mean it’s a redirect, it purely links it to the other records address :slight_smile:

1 Like

Imagine DNS and redirects like signs.

A CNAME tells you to go to the other’s address (for example, 1.1.1.1), whereas a redirect actually says “go to this other domain” (for example, from sub.example.com go to example.com).

2 Likes

I have just done the above and unfortunately it still does not seem to be working, when testing it by typing blog.example.com to see if it redirects to www.example.com, it gives site can’t be reached/DNS_PROBE_FINISHED_NXDOMAIN error. Have tried on a different network, and also tried setting the destination url to just be example.com, but neither work.

That’s likely a DNS caching issue on your local computer. Try taking a look on Google about how to clear you DNS cache (it varies based on operating system and browser, you’ll need to clear both usually) or try on another computer/network entirely.

Thanks, turns out I’d made a typo in my URL - all seems to work now, thanks for the help.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.