Cloudflare provides lots of special pages that could be served directly from CF, not making request to origin server.

Cloudflare Custom Pages list: basic_challenge, waf_challenge, waf_block, country_challenge, ip_block, under_attack, 429_errors, 500_errors, 1000_errors.

We interested in two custom scenarios - block request, block country.

In firewall settings it's easy to block / allow some county list.

Firewall Rule to block country in CloudFlare

But if you have PRO plan and want to customize block page you will face one strange problem. Firewall rules to block handled by 1000 custom page, not by country block custom page.

In terms of CF county block is WAF feature available in enterprise plan.

It means that we can't split country block and other blocks (by ip, user agent etc).

The next problem is about showing geo dependant content. For example in UK we want to show UK flag, but in USA - we want to show some additional referral link.

There is no way to do different pages for different countries, but we can do small hack.

At 1000 custom page page special tag is available ::geo:: (it's not mentioned in docs for that kind of pages, but it works).

::geo:: will be substituted to country ISO code in uppercase, like UK, UA, DE, etc.

Nothing stops us from putting geo code into CSS class.

<body class="::geo::">
	<div class="hidden UK">UA block shown only for UK visitors</div>
</body>

We even don't need js to get use of it. Depending on base css class with county name we can show/hide dependant blocks.

.hidden {
	display: none;
}

.UK .UK.hidden {
	display: block;
}

If we want to do some scripting, free to get geo params in JS.

var geo = document.body.classList.value;

Ми наймаємо

Захоплюєтесь новими ідеями, хочете рости професійно й досліджувати можливе.

Це про вас?
Відкрийте кар’єрні можливості в NodeArt.

Вакансії