Redirect a subdomain in Cloudflare

You want to point your subdomain using Cloudflare's nameservers to elsewhere. Here's how.

Disclaimer: This article takes into account that you are already using Cloudflare's nameservers on your domain.

Cloudflare in comparison to other domain registrars makes it a little weird to redirect a subdomain elsewhere.

Instead of using a simple 301 Forward on the DNS section of your Cloudflare dashboard, you have to use Cloudflare's page rules and a CNAME record (ironically, on the DNS section). Let's start.

Configure Cloudflare's page rules


Login to your dashboard and select the domain you want to configure.

Then, navigate to the page rules tab of your Cloudflare dashboard. This is not under DNS, instead it is under its own section, the "Rules" tab. You can also select it on the right section of "Overview".

Cloudflare's domain overview dashboard.
You'll find it below "Active Subscriptions".

Once you're on the page rules tab, go ahead and click on "Create Page Rule" button.

Rules' Page Rules section.
Select "Create Page Rule".

Type the URL (without https://) that you want to be redirected to another domain. In this case, I want to redirect status.juanca.org to elsewhere.

If you want a catchall redirection rule, so if the domain matches anything under that route, it will redirect to the new location, use /* after the domain. The end result would be status.juanca.org/*.

Under "then these settings are", select the forwarding URL option with the 301 option if you want a permanent redirect.

Finally, enter the URL that you would like your Cloudflare domain to redirect to within the respective input field. In this case, that would be https://www.juancastatus.org.

Create a Page Rule for juanca.org page
When you are done, click the "Save and Deploy" button.

After saving, this should be your end result on the "Rules" page.

Page Rules with new rule added.
We are almost finished!

Apply the rule, and your old domain will now forward to the new one, right? Wrong. There's one more step.

The caveat: a CNAME record


Finally, add a CNAME record which redirects to @.

In this case, we'll add a CNAME record for status to @. Don't forget to proxy through Cloudflare! (the orange cloud toggle, "proxy status").

DNS management menu adding the CNAME record.
The final step.

Now everything should be working now! https://status.juanca.org will redirect to https://www.juancastatus.org with this config.

For reference


From the hidden Cloudflare's FAQ page:

Why isn't a Page Rule working?

The number one reason that a Page Rule isn't working, such as URL forwarding, is that the Page Rule you created is on a record that is not proxied by Cloudflare in your DNS settings.

Example: You have a Page Rule that redirects a subdomain (subdomain.yoursitename.com) back to your root domain (yoursitename.com). If you do not have that record proxied in your DNS settings for the subdomain record (orange cloud), Cloudflare's proxy is not running over the record and a Page Rule will not work because it is going direct to your server.

Also, shout out to Kevin Cooper for his Stack Overflow answer.