Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare DNS - How to redirect all subdomains to root domain?

Can somebody tell me how I can redirect all subdomains to the root domain in Cloudflare DNS?

I have been looking for a day now without any luck.

I can't use .htaccess because all the subdomains doesn't resolve (They look just like a root domain that haven't propagated) and doesn't return anything, and I don't want to set up hundreds of DNS records for each possible subdomains.

I would like to set up a wildcard dns entry to redirect or at least make all subdomains reachable, so I can either do the rest via the .htaccess, or through DNS.

So how do I make the DNS entry for above requirements?

Thanks.

like image 592
JDoe Avatar asked Aug 28 '17 10:08

JDoe


1 Answers

From the support: Does Cloudflare support wildcard DNS entries?

Cloudflare Free, Pro and Business plan:

We do not proxy wildcard records so these subdomains will be served directly without Cloudflare performance, security, or apps. The wildcard domain will have no cloud (orange or grey) on the Cloudflare DNS Settings page for that reason. If you are adding a * CNAME or A Record you need to make sure the record is grey clouded in order for the record to be created.

To get Cloudflare protection on a wildcard subdomain (for example: www), you explicitly have to define that record in your Cloudflare DNS settings. First, log into your Cloudflare account and select the DNS icon. In this example, you would add "www" as its own CNAME record on your Cloudflare DNS Settings page and toggle the cloud to orange so the Cloudflare's proxy is enabled.

Unless you are an Enterprise customer, you can't use a wildcard to redirect through Cloudflare.

Make sure the cloud logo is grey to add a wildcard record:

Cloudflare DNS: CNAME * example.com

like image 114
LEI Avatar answered Sep 30 '22 08:09

LEI