How To Redirect A Subdomain to Main Domain In Cloudflare

How to Redirect A Subdomain to Main Domain In Cloudflare

Table Of Contents

Share Article

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 will be redirected to or

Cloudflare allows you in the free version to use 3-page rules, so you can have up to 3 custom redirects directly in Cloudflare.

Steps to Redirect the Subdomain to Main Domain in Cloudflare.

1. Proxy the Subdomain to 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:

2. Add the Page Rule in Cloudflare

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:

  • URL Match:*
    This will assure that http and https traffic will be picked up. Also the * will catch the page that is accessed and will be transmited further.
  • For Settings: Forwarding URL and 301 – Permanent Redirect
    This are the setting that will tell cloudflare what to do.
  • URL to be Forwarded to:$1
    This will tell Cloudflare what to use when matched URL is seen. The $1 will send the same request further. This is very important as you want to keep the same pages for SEO purposes.
1. Page Rules
2. Create Page Rule
3. Rule Example


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.

Become a CloudPanel Expert

This course will teach you everything you need to know about web server management, from installation to backup and security.
Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Hi,

    I followed your video and its worked.

    Thank you.