If you are using Cloudflare as your DNS manager you can also use it to do redirect directly in there without a need for an additional web server. A while back I have created the video for redirecting non-WWW to the WWW website so if you need that you can watch it.
In this article and video, we will 301 redirect a subdomain to the main domain, everything will be redirected so in case you have a blog.domain.com/article-1 will be redirected to domain.com/article-1 or domain.com/blog/article-1.
Cloudflare allows you in the free version to use 3-page rules, so you can have up to 3 custom redirects directly in Cloudflare.
In case your subdomain doesn’t have the proxy activated you need to activate it as otherwise will not work. It doesn’t matter what you have for the main domain or other subdomains, what needs to be proxied thru Cloudflare is the subdomain you want to be redirected as in bellow picture:
Next, you need to enable the page rule that will tell Cloudflare what to do when the subdomain is accessed. Go to Rules > Page Rules in Cloudflare and add the bellow settings:
These are all the steps you need to do to redirect your subdomain to the main domain in Cloudflare. The only downside is that you have only 3 rules that you can add with the free account so you need to choose them in function of the needs.