Block visitors with certain browser language

I’m looking for a way to block visitors with certain browser language.
I found that there is a string like this http.request.accepted_languages but it wasn’t accepted in in the Transform rules form.
Let’s say I need to show chalange to all visitors with browser language ‘en’ but not for ‘en-US’ or ‘en-CA’. What should be the exact rule for that purpose?
I tried (http.request.accepted_languages eq “en”) but it wasn’t accepted by CF.

'(http.request.accepted_languages eq “en”)' is not a valid value for expression because the expression is invalid: Filter parsing error (1:34): (http.request.accepted_languages eq “en”) ^^ cannot perform this operation on type Array(CompoundType { layers: 0, len: 0, primitive: Bytes })

It’s an array rather than a single string.

You’d use the any function.

any(http.request.accepted_languages[*] == "en")


Thank you for asking.

Furthermore, language tags are formally defined in RFC 5646, which rely on the ISO 639 standard (quite often the ISO 639-1 code list) for language codes to be used.

We could catch the requests from visitors based on a Web browser language, therefrom redirect them to some non-existing page or redirect them away, or even display a default Cloudflare’s 1020 Access Denied error page using a combination of the Transform Rules & Page Rule / Firewall Rule.

1 Like

Thanks to [KianNH] and [fritex] for prompt answear.

When I use the rule suggested by KianNH

any(http.request.accepted_languages[*] == “en”)

there is a following error
cannot use field http.request.accepted_languages, not available to this plan/phase, at index: 0

What might be wrong with it?

Where are you attempting to use it?

It’s only available in Transform Rules for adding request headers.

imho I don’t think it’s useful for what you’re trying to do.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.