How to Add a Cloudflare Rule for WP Login: Secure wp-login.php and Reduce Brute-Force Attacks

Written by: Abigail Ivy
Published on:

Why protect wp-login.php with a Cloudflare rule?

The WordPress login page is a common target for brute-force attacks, credential stuffing, and automated bot traffic.

If you know how to add Cloudflare rule for wp login, you can block unnecessary requests before they reach your server and reduce load on your hosting stack.

Cloudflare is especially useful because it sits in front of your origin server and can inspect requests at the edge.

That gives you several ways to protect wp-login.php without changing WordPress core files or installing heavy plugins.

What you need before creating the rule

Before you configure anything, make sure your site is already proxied through Cloudflare and your DNS records show the orange cloud icon.

You should also know whether your login path is the default /wp-login.php or a custom login URL created by a security plugin.

  • A Cloudflare account with access to the correct zone
  • Your WordPress login path
  • Optional: your office IP address or VPN IP address for allowlisting
  • Optional: a staging environment for testing changes first

If you use Cloudflare WAF, Firewall Rules, or the newer Rules language, you can apply controls with different levels of precision.

The exact menu labels may vary slightly depending on your plan and interface updates.

How to add Cloudflare rule for wp login

The most common approach is to create a rule that specifically matches requests to wp-login.php and then apply a security action.

You can challenge suspicious visitors, block untrusted traffic, or allow only approved IP addresses.

Step 1: Open the Cloudflare rules section

Log in to Cloudflare, select your domain, and go to the rules area in the dashboard.

Depending on your interface, look for Security, WAF, Rules, or Firewall Rules.

Step 2: Create a new rule

Choose to create a custom rule or firewall rule.

Give it a clear name such as Protect WP Login so you can identify it later if you need to troubleshoot or adjust the policy.

Step 3: Define the match condition

Use a request filter that targets the WordPress login page.

A common expression is:

http.request.uri.path contains "/wp-login.php"

You can make the rule narrower by also matching POST requests, which are used when users submit login credentials:

http.request.uri.path eq "/wp-login.php" and http.request.method eq "POST"

This is useful if you want to challenge or block login submissions while leaving the page itself accessible for visitors who need to view it.

Step 4: Choose an action

Select the action based on your security goal.

Common options include:

  • Block — stops requests immediately
  • Managed Challenge — lets Cloudflare decide whether to show a challenge
  • JS Challenge — verifies browsers with JavaScript
  • Allow — permits trusted traffic, such as your office network

For most WordPress sites, Managed Challenge is a balanced starting point because it reduces bot activity without shutting out legitimate users as aggressively as a hard block.

Recommended rule patterns for WordPress login protection

There is no single best rule for every site.

The right setup depends on whether you want to protect a public login page, limit logins to specific IPs, or reduce attack volume while keeping normal access simple.

Challenge only wp-login.php

This is the easiest option when you want to slow brute-force attempts without disrupting normal site browsing.

Match /wp-login.php and apply a Managed Challenge.

Allow only trusted IP addresses

If only staff, contractors, or administrators should access the login page, create an allow rule for known IP ranges and then block everything else on /wp-login.php.

This is one of the strongest protections for internal dashboards.

Example logic:

  • If IP is in your office range, allow
  • If request targets /wp-login.php and is not from a trusted IP, block or challenge

Protect POST requests only

If you want visitors to reach the login screen but prevent automated credential submissions, target login POST requests.

This can reduce the chance of false positives for people simply loading the page.

Combine login protection with rate limiting

Cloudflare rate limiting is useful when a single IP repeatedly hits the login endpoint.

You can trigger a challenge or block after a threshold such as several requests in a short window.

This adds another layer beyond a basic firewall rule.

Example Cloudflare rule expressions

Below are practical examples you can adapt for your site.

Always test expressions carefully before enforcing them on production traffic.

Basic login page rule

http.request.uri.path eq "/wp-login.php"

Use this when you want to apply a policy to every request to the login page.

Login POST protection

http.request.uri.path eq "/wp-login.php" and http.request.method eq "POST"

Use this to focus on credential submission attempts.

Allowlist specific IP addresses

ip.src in {203.0.113.10 203.0.113.11}

Use this in an allow rule for admin offices, VPN gateways, or a trusted support team.

Block non-allowed login traffic

(http.request.uri.path eq "/wp-login.php") and not ip.src in {203.0.113.10 203.0.113.11}

Use this when only a few IPs should ever reach WordPress login.

How to avoid common mistakes

Cloudflare rules are powerful, but a small configuration mistake can lock out administrators or break workflows.

Careful testing matters, especially on high-traffic or multi-author WordPress sites.

  • Do not block all traffic blindly if your team logs in from changing IP addresses
  • Check custom login URLs if a security plugin renamed wp-login.php
  • Test from a mobile network to confirm visitors can still log in if needed
  • Review WooCommerce and membership flows if your site uses account login pages
  • Consider admin access requirements for remote workers and agencies

If you use two-factor authentication, SSO, or an application password workflow, confirm that Cloudflare challenges do not interfere with those steps.

Authentication systems that depend on redirects or embedded requests may need exceptions.

How Cloudflare compares with WordPress security plugins

Security plugins like Wordfence, iThemes Security, and Sucuri can protect login pages from inside WordPress.

Cloudflare complements those tools by filtering bad requests before they hit PHP, MySQL, or the WordPress admin area.

A Cloudflare rule is often better for reducing server load and absorbing large-volume attacks.

A plugin is often better for application-level checks, detailed login logging, and user-focused controls such as reCAPTCHA or 2FA prompts.

In many cases, the best setup combines both approaches:

  • Cloudflare handles edge filtering and bot mitigation
  • WordPress handles authentication, role control, and audit logging

How to verify that the rule works

After saving the rule, test it from a browser and from an IP address that should be challenged or blocked.

Review Cloudflare security events to confirm whether the traffic matches the rule as expected.

Useful checks include:

  • Loading /wp-login.php in a normal browser session
  • Submitting a test login from a trusted network
  • Checking firewall logs for challenged or blocked requests
  • Confirming that legitimate users are not seeing error loops

If the rule is too aggressive, adjust the match condition rather than removing protection entirely.

For example, narrow it to POST requests or add explicit allow rules for trusted IPs.

Best practices for long-term WordPress login security

Cloudflare rules work best as part of a layered security strategy.

Keep your login defense current by reviewing who needs access, which IP addresses are trusted, and whether your login page is publicly necessary.

  • Use strong passwords and unique admin credentials
  • Enable two-factor authentication for administrators
  • Limit the number of administrator accounts
  • Keep WordPress, themes, and plugins updated
  • Monitor Cloudflare security events regularly
  • Use rate limiting for repeated login attempts

When configured well, Cloudflare can significantly reduce brute-force pressure on WordPress while keeping the admin experience usable for your team.

The key is choosing the right match conditions and applying the least restrictive rule that still protects the login surface.