Problem making redirection from subdomain to main domain

Hello,

I am trying to make redirection from the subdomain http://www.doc.mydomain.com to https://www.mydomain.com

I want for redirection to be wildcard so when any url from that subdomain is hit redirects to main domain.

I had made A record on DNS to my server IP, I had create redirection on cpanel and also I had created foward url on page rules.

The problem I am having is that it seems it only redirects url from subdomain to main domain and what I want is a wildcard redirect so every url from that subdomain redirects to main domain, how I can fix this? also do I have to put any wildcard setting when subdomain is hit with nonwww?

Thanks!

Two possible issues:

  1. the Cloudflare certificate (for practical reasons) covers only first-level subdomains (covers sub.example.com and not sub.sub.example.com). You need an advanced certificate for that, it’s 10$/month.
  2. an actual wildcard record exists (you can put *.www as an A record), but it won’t be proxied by Cloudflare unless you are on the Enterprise plan, so you’ll need to do that on your own server.

Hey matteo,

Thanks for the reply, just one thing what about if I make on my server nonwww redirection for subdomain and then on cloudflare I just do first-level redirection to main domain, would that work? and would redirection be wildcard?

On your server, you can do whatever, but then I would redirect directly to the final domain, never do double redirect if possible.

But would it work or not?

Of course it would, you just can’t proxy via Cloudflare if you set-up a wildcard domain so the connections will go directly to the origin.

But lets say that I create on my server redirection from http://www.subdomain1.mydomain.com to http://subdomain1.mydomain.com and on cloudflare I do wildcard redirection from that subdomain to main domain and I dont have to do wildcard A record *.subdomain1 just do regular A record with subdomain1.

Is there any problem by doing that?

No. You do still need to add a record that points to your server, I would presume a wildcard, which won’t be proxied, but it works.

I would still redirect directly to the correct one, without the double redirect to speed up things, but do as you please.