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

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.

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:

Related

How to configure DNS for Azure CDN with multiple endpoints and root

I own a domain "x.wiki" which is managed via domains.google
I have a website, which is split up into multiple endpoints using azure cdn.
sub1-x.azureedge.net - Subdomain 1 (intended site route with all content)
sub2-x.azureedge.net - Subdomain 2 (subdomain with limited
content)
sub3-x.azureedge.net - Subdomain 3 (subdomain with limited
content)
I want to serve these as follows.
www.x.wiki -> sub1-x.azureedge.net
x.wiki -> sub1-x.azureedge.net
sub2.x.wiki -> sub2-x.azureedge.net
sub3.x.wiki -> sub3-x.azureedge.net
currently it only works with www. / sub2. / sub3.
x.wiki doesnt resolve
Does anyone know how I can get this working correctly?
My understanding is that due to limitations with CNAME i cannot do this easily, however azureCDN to my knowledge does not give me an IP for use with custom domains.
Here is my DNS configuration.
You also use alias records to point your DNS zone apex x.wiki to Azure CDN endpoints. If your domain DNS provider does not support alias record for root domain, you could optionally to host your domain in Azure DNS.
In the Azure DNS zone, you could create an alias record like this,
Then, you will see one A record and one CNAME for your CDN endpoint.
After the records are verified, you could add the hostname x.wiki in the custom domain of your CDN endpoint.
Alternatively, you could try the workaround in this blog.
Set up a CNAME “cdnverify.” to
“cdnverify..azureedge.net”. Once all is verified and set up
(including SSL provisioning if desired), delete the CNAME and use
ANAME for the root record.
The answer to this is to redirect root to WWW from my DNS provider.
The cdnverify cname is not necessary.
https://www.tachyonstemplates.com/2018/google-domains-forward-root/
May re-open this if i still cant get adsense to resolve the root (because it is a redirect)

How to redirect naked domain to www in Google Domain?

I have a domain name mydomain.com registered at Google Domain. I would like to use it for a static website in Azure.
I would really love to use my naked domain rather than the www version, but I don't think it is possible since when I try to create a CNAME from mydomain.com, I get CNAME records for the root domain are not supported. If anyone has a solution, I am interested.
Custom domain in Azure portal tells me to create a CNAME from www.mydomain.com to diamnis.z16.web.core.windows.net, which I did.
Now, how do I get traffic from the naked domain mydomain.com to go to www.mydomain.com in Google Domains?
You can do that in google domain dns. Follow the below steps -
After you have done the CNAME mapping for www.chartvibes.com, do as mentioned below -
To configure the naked domain, add a "Synthetic Record", and set up a
"Subdomain Forward." In the subdomain text box, enter the # sign and
nothing else.
Select option to 'Forward path'. That should do the root domain forwarding.
You can refer to the below official link too - https://support.google.com/domains/answer/4522141

DNS: forward root domain to www... when there are other DNS subdomains

I currently have a DNS setup where all content and applications are hosted on the same cloud server - example.com.
The presentation website is on example.com, www is forwarded to example.com with a CNAME and then various internal apps, eg app.example.com, are also forwarded with CNAME records to example.com. NGINX running on my server takes it from there, routing subdomains to the different apps.
I'd like to host the presentational website on an external service, and I'm confused about how to update my DNS config - specifically what to do with my A record.
I'm ok with creating a CNAME for www that will forward www.example.com to my external hosting service. But example.com is still pointing to my own server... and if I have understood correctly, if I forward example.com to www.example.com, then all my apps at eg app.example.com will break.
What are my options for handling this ?
My idea (from searching around) is that if I want example.com to point to an external service, then I should
1) create a new domain api-example.com whose A record points to a server where all my apps are hosted
2) make CNAME records for all my app subdomains on example.com which point to api-example.com
3) forward example.com to www.example.com, and forward www.example.com to the external service.
Will this configuration work ? Is there a simpler way to get the same result ?
Your plan is fine, except for maybe one thing: generally, you can't have a CNAME record for the root (apex) of your domain. This means that your external presentation website hosting will have to provide an IP address, and you will create an A record that will point example.com to that address. Then you can have a CNAME record simply aliasing www.example.com to example.com.
Also make sure that you leave enough time between the steps, to make sure that all DNS TTLs expired so you don't encounter DNS caching issues.
For explanation (and possible workarounds) for domain apex CNAMEing issue, look at https://stackoverflow.com/a/33027309/1145196

Domain without WWW on Cloudflare?

I created an app on Openshift and added aliases.
My registrar doesn't allow me to add a CNAME without WWW. So I started using the Cloudflare DNS servers and added 2 CNAME records. In the records page it looks like this:
CNAME porta8080.com.br is an alias of blog-porta8080.rhcloud.com Automatic
CNAME www is an alias of blog-porta8080.rhcloud.com Automatic
I changed it like 3 or 4 ours ago and the domain status is already Active.
If I go to my website it won't be displayed if I omit the subdomain www. . But works well with www.
I wonder if I can do this with Cloudflare (with and without www.) and/or cloudflare is alrady routing for me. I got a free plan.
Thank you
#edit
Now I got a ERR_TOO_MANY_REDIRECTS error. Any ideas on what could this be?
CloudFlare Partner set-ups usually are done via a CNAME set-up. Unfortunately it doesn't strictly comply with an RFC to support a CNAME record on a root domain, accordingly you can either set-up your own CloudFlare account (you won't get RailGun if your host are not just a normal CloudFlare Partner but an Optimised Partner).
The way around this is either get them to support the Full Host set-up which CloudFlare now support or set-up your own CloudFlare account and use a nameserver install.

DNS Settings: OpenShift with CloudFlare / rhcloud

I am trying to set up DNS forwarding on CloudFlare, to my Openshift page (the-domain.rhcloud.com).
But when I go into the CloudFlare DNS settings and try to change the A setting, I get this error:
You entered 'the-domain.rhcloud.com' which is not a valid IP address.
It seems to be asking for a static ip address. It seems that other hosting services can provide a numerical ip address for DNS settings, but I cannot find anything like that on rhcloud / OpenShift.
How can I find my domain's ip address on rhcloud OpenShift? What should basic DNS settings look like on CloudFlare when forwarding to an rhcloud host?
Should I use any of the default A and AAAA settings from my registrar?
It's a bit unusual, but when using services like Openshift/Heroku etc, there is no A record for the domain in your DNS. This is because there is no single A record corresponding to your site or app on the service.
If you've already set up the domain at your registrar using Cloudflare's nameservers (you need to do this!) there should be no need to do anything else at the registrar.
You need to set up one (or more) CNAMEs for the site/app at Cloudlare (if it's a website, you may want one each for e.g. example.com and www.example.com).
Assuming you do need the 'naked' domain and the www version, you'd do this:
Openshift
Make sure you have domains set up for both the 'naked' domain and the www subdomain.
Cloudflare:
Back it up!
Cloudflare lets you export your DNS settings; do this before making any changes.
Naked domain
go to the DNS settings page
choose CNAME from the selector at bottom
enter the-domain in the first field
enter the-domain.rhcloud.com in the second ("is an alias of") field
www subdomain
repeat steps 1-4 from above, but enter www for step 3.
go to the "Page Rules" page
add a new "page forwarding" rule that either:
redirects http://the-domain.com/* to http://www.the-domain.com/$1 or
redirects http://www.the-domain.com/* to http://the-domain.com/$1
choose '301' for the redirect type
If you want your domain name to start with https://www, take a look at the steps bellow that worked for me.
Let's say we want to configure cloudflare and openshift for this domain name: example.org.
Cloudflare
DNS page
I have two records set:
Type: CNAME Name: example.org Value: example-example.rhcloud.com (you should see CNAME flattening sign for this one)
Type: CNAME Name: www Value: example.org
"Page rules" page
Two rules:
http://www.example.org/* Settings: Always use HTTPS
example.org/* Settings: Forwarding url, 301 — Permanent redirect, https://www.example.org/$1
OpenShift
Add one alias:
www.example.org

Resources