Security

Protect your website with Cloudflare WAF custom rules

Use Cloudflare WAF custom rules to block bad countries, bots and attack paths, challenge visitors to wp-login.php, and allow your own IP, before traffic reaches your hosting.

IntermediateSites using Cloudflare2 min read

When your domain uses Cloudflare as a proxy (orange cloud), every request passes through Cloudflare first. Its web application firewall (WAF) can block or challenge unwanted traffic at the edge, so attacks never reach your MdmHost server and do not use your account's resources.

Before you start

  • A domain added to Cloudflare with its DNS records set to Proxied.
  • SSL set to Full (strict); see Cloudflare Full (strict) SSL.
  • Custom rules are available on the free plan with a limited number of rules; managed rulesets need a paid plan.

Open the WAF

  1. Log in to the Cloudflare dashboard and choose your domain.
  2. Go to Security → WAF → Custom rules.
  3. Click Create rule. Each rule has a name, an expression (when it matches) and an action.

Actions you will use most:

ActionEffect
BlockVisitor gets a Cloudflare block page.
Managed ChallengeCloudflare decides whether to show a check; humans usually pass automatically.
SkipLet matching traffic bypass other rules, for example your office IP.

Useful rules

Protect the WordPress login

Use Edit expression and paste:

(http.request.uri.path contains "/wp-login.php") or (http.request.uri.path contains "/xmlrpc.php")

Action: Managed Challenge. This stops most brute-force bots. More options are in protect wp-login and XML-RPC.

Allow your own IP first

(ip.src eq 203.0.113.10)

Action: Skip all remaining custom rules, and place this rule at the top of the list.

Block countries you never serve

(ip.src.country in {"XX" "YY"})

Replace the codes with two-letter country codes. Prefer Managed Challenge over Block if real customers could travel.

Block common exploit paths

(http.request.uri.path contains "/.env") or (http.request.uri.path contains "/.git")

Action: Block.

Warning: Do not challenge /wp-admin/admin-ajax.php, /wp-cron.php, payment gateway callbacks or API endpoints. Machines cannot solve challenges, so those features would break.

Check afterwards

  • Open Security → Events to see which rule matched each request, and adjust rules that catch real visitors.
  • Because visitors now arrive from Cloudflare IPs, make sure your server logs the real visitor IP. On LiteSpeed servers this is handled automatically; on Nginx see Nginx real IP behind Cloudflare.
  • An attacker who knows your server IP can bypass Cloudflare. Do not publish it in DNS records such as an unproxied direct A record.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.