Add custom header if the request is a known bot?

Hi. As stated in the question, I am trying to add a custom header from Cloudflare so that my server app (PHP) can detect if the request is made from a known bot. There is a similar, perhaps even identical question with a solution in the link below. However, this does not seem to work any more, because Transform Rules > Modify Request Header no longer has “known bots” selector, like “Modify response header” has.

So basically I would like to ask if anyone has any updated solution for this?

Hi,

Have you tried using the rule expression (cf.client.bot)

I actually tried that earlier, and re-tried again right now with your example, but it simply doesn’t seem to be triggering on server. I have checked while having visits from Petalbot (verified category). PHP if(isset($_SERVER['X-Known-Bot'])) log_something() ... … Nothing …

Besides, if cf.client_bot is available from “Modify Request Headers”, then why doesn’t it display in the dropdown selector? It does display under “Modify Response Headers”, which seems inconsistent.

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