Create a redirection from one subdomain to other

I want to redirect all traffic from multiple (60+) subdomains to one URL. I don’t want to buy 60+ page rules so I decided to create just one page rule for one subdomain and redirect all other subdomains to the subdomain with rule.

So let’s assume that we have domain1.some_domain.com. It’s redirected to another_domain.com/some_url via page rule.

Now I want to connect all other subdomains (domain2.some_domain.com, domain3.some_domain.com) to the domain1.some_domain.com. How can I do that?

How this setup looks like now:
CNAME domain1.some_domain.com points to example.com (literally, I’m not hiding it). This subdomain also has a page rule that redirects all the traffic to https://another_domain.com/some_url
CNAME domain2.some_domain.com points to domain1.some_domain.com.

All domain entries are proxied. Also account has a SSL mode “Full (strict)”.

Now when I’m trying to get domain2.some_domain.com I’m getting a 526 error (Invalid SSL certificate). How can I fix it? May I create a direct DNS record to redirect users from domain1.some_domain.com to https://another_domain.com/some_url instead of using page rule?

Thank you in advance!

You can do this via a worker or by creating a page rule

See https://developers.cloudflare.com/workers/examples/redirect for more info on create a worker redirect

See https://support.cloudflare.com/hc/en-us/articles/200172336-Creating-Page-Rules on creating a page rule (without creating a worker)

CNAME really isn’t going to cut it. But since they’re all there and :orange:, then that’s a good start.
This should work with just two page rules, assuming the only other “subdomain” you have is ‘www’.

Rule #1: Match www.example.com/* with a Setting of Cache Level “standard” (or some other setting that doesn’t change how the site already works. This is a place holder rule so Rule #2 doesn’t trigger for the ‘www’ subdomain.
Rule #2: Match *.example.com/* with a Setting for Forwarding URL to your destination.

3 Likes

Thank you for your help! I really appreciate that! Unfortunately options you suggested don’t fit my needs since I need to create those rules on-the-fly. That means I’ll have one rule per subdomain (60+ rules) or I’ll have to modify the worker code after adding each subdomain which is also inconvenient.

BTW, thank you for your help!

Thank you a lot! I’ll try to implement your suggestions on my project tomorrow. I’ll let you know if it would be successful. Thank you again!

1 Like

Unfortunately, that option will not fit my needs. I would consider other services like Easyredir. Thank you for your time and your help!

1 Like

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