大网数据广告活动
网站运营与故障问答

Cloudflare WAF rule for blocking a path except from two countries instead block all traffic to the site

· 52CE 我爱测

I want Cloudflare WAF to restrict admin section of WordPress site /wp-admin/ and allow access to WP admin section from only two countries India & UAE. For some reason it block traffic from all countries not only to admin section …

问题原文

原帖链接 · Learning · CC BY-SA 4.0

I want Cloudflare WAF to restrict admin section of WordPress site/wp-admin/ and allow access to WP admin section from only two countries India & UAE.

For some reason it block traffic from all countries not only to admin section but also to main website such as www.example.com.

To me below setting should only block admin pages from all countries other than India & UAE and main site should not have any restriction.

Not sure if I am doing anything wrong here as its not working as intended.

Second image :

Third Image: Fourth Image Fifth image

已采纳解答

原帖链接 · Matteo Manfredi · CC BY-SA 4.0

This is the easy way, supported in all cases. Limit Hostname with equals example.com, URI Path with contains /wp-admin or /wp-admin/ (this is shown in the screenshot below), and Country with is not in { "IN", "AE" }.

If you have access to it (depending on plan type), using a matches regex could make the URI Path filter easier and more focused as it becomes ^/wp-admin, meaning it blocks all those that start with that path.

The full expression, which you can enter when you click "Edit expression" then becomes:

(http.host eq "example.com" and http.request.uri.path contains "/wp-admin/" and not ip.geoip.country in {"IN" "AE"})

The error you are encountering is because you are using OR after the AND group, meaning it's blocking all request to all hostnames and all paths not coming from the UAE or all the requests not coming from India limited to the specific filter you added to the URI in each screenshot.

This you can clearly see in the expression preview below each example.

In your case, if you really wanted to keep the OR in there (isn't required, as shown above, but to show all possible cases), you'd need to filter the URI in each section of Country filtering, before and after the OR.


More info on this can be found in:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2022-09-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。