Block country access to subdomain then redirect

I have a specific subdomain that I want to restrict access to. I know that in the firewall rules, I can specify countries to block. What I would like to do is prevent access, but then redirect to a specific page outside of that subdomain, which provides an explanation as to why they were blocked. E.g:

[Bad country] → [Blocked] → [Redirected]

Can I achieve this using Cloudflare?

The Block page is a specific Cloudflare Error page that can be customized, but anybody who got blocked by the firewall would see the same page.

I think this has been asked before and someone suggested writing a Cloudflare Worker, but I don’t know if they were successful. @matteo may remember the discussion.

Thank you! Found this in “Custom Pages” – It’s exactly what I’m looking for.

1 Like

Hi @user9785.

I guess Custom Pages for IP/Country Block is related only to rules from Firewall > Tools.

However, to relate countries and hostnames/paths in a single rule, the feature you need to use (without considering Workers) is Firewall > Firewall Rules.

And so, the page displayed would not be the one that was customized. (Maybe the WAF?)

Anyway, I’m not sure about that. Could you clarify, @sdayman ?

I think it’s going to work. That IP/Country block looks like the error page that’s triggered by Firewall Rules. There’s a Country Challenge farther down, but that’s a challenge, and not a block.

But I could be wrong. Experimenting is fun.

1 Like

Custom pages might work but that is different from what you originally asked for.

Custom pages will allow you to customise the page which generally appears for blocked requests. That wont be country specific though. Also, that would not only apply to the payment host but domain wide.

It might work, but as @sdayman already mentioned Workers would be the only approach to implement this as requested.

1 Like

I’m a bit confused now. There are two pages I see in Custom Pages:

  1. IP/Country Block (Customize the error page shown to your visitors when they visit from a blocked IP address or country.)

  2. Country Challenge (Customize the challenge page presented to visitors from countries you have selected to block.)

Are you saying that neither of these options will trigger the way I want to?

You are talking about blocking, so the challenge page wouldnt be relevant here in the first place.

What is it exactly you want to achieve? Just show a customised text when a request is in general blocked or something when requests from specific countries are blocked?

@sandro When requests from specific countries are blocked. But in a pinch, I could generalise the message. But I only want to block a specific host name (subdomain) and only specific countries.

Well, as I mentioned earlier you can simply use the custom page you initially referred to to set up a generic page which is displayed for all blocked requests. Then you simply use firewall rules to block requests based on the hostname and country, in which case your custom page will be displayed. However you should note that this page will be also used for all other requests which might happen to get blocked, so set up a generic message.

1 Like

Thank you!

This topic was automatically closed after 31 days. New replies are no longer allowed.