5 Cloudflare rules to secure your WordPress site
Five Cloudflare WAF custom rules for WordPress: protect wp-login and wp-admin, handle xmlrpc.php, block PHP in uploads and bypass cache for admin.
At a glance
Five Cloudflare rules cover most WordPress sites: challenge the login page, challenge wp-admin except the AJAX endpoints, restrict xmlrpc.php, block PHP files in the uploads folder, and keep admin pages out of the cache. This guide gives the expression for each rule, the action to use, how to test them, and how to protect the origin server so the rules cannot be bypassed.
Updated November 29, 2026 · For WordPress site owners and developers using Cloudflare
- For WordPress owners and developers who use Cloudflare in front of their site
- Rules login challenge, wp-admin challenge, xmlrpc block, PHP-in-uploads block, admin cache bypass
- Where Security, WAF, Custom rules, plus a Cache Rule for caching
- Risk a careless rule can lock out you or visitors, so add your own IP as an exception
- Not a replacement for updates, strong passwords, two-factor login and a clean site
- Help security service or emergency support if a site is already compromised
On this page
- What are the five rules at a glance?
- Where do I add the rules?
- Rule 1: challenge the login page
- Rule 2: challenge wp-admin, but not admin-ajax
- Rule 3: restrict xmlrpc.php
- Rule 4: block PHP files in the uploads folder
- Rule 5: do not cache admin or logged-in pages
- What about the threat score rule?
- What else protects the origin?
- How do I test and maintain the rules?
- What can go wrong with each rule?
- FAQ
Cloudflare can stop a lot of junk traffic before it reaches your server. Five rules cover most WordPress sites: challenge the login page, challenge wp-admin (except the AJAX endpoint), restrict `xmlrpc.php`, block PHP files in the uploads folder, and keep admin pages out of the cache. Write each carefully, because a wrong rule can lock out you or your customers.
What are the five rules at a glance?
| Rule | Path | Action |
|---|---|---|
| 1. Login page | /wp-login.php | Managed Challenge |
| 2. wp-admin | /wp-admin, except admin-ajax.php and admin-post.php | Managed Challenge |
| 3. xmlrpc | /xmlrpc.php | Block, if unused |
| 4. PHP in uploads | /wp-content/uploads/*.php | Block |
| 5. Admin and logged-in pages | admin, login, logged-in cookie | Bypass cache (Cache Rule) |
Before you start, note your current Cloudflare settings.
Where do I add the rules?
In Cloudflare, choose your domain, then Security, WAF, Custom rules, Create rule. Enter a name, edit the expression, choose an action and deploy. Cloudflare evaluates rules in order, so put "allow" rules for your own IP above the challenge rules. Free plans have a small rule allowance, which changes, so check yours.
Rule 1: challenge the login page
(http.request.uri.path eq "/wp-login.php" and ip.src ne 203.0.113.10)Set Action to Managed Challenge. Replace 203.0.113.10 with your own fixed IP, or remove that part if yours changes. Do not use Block here, since mistakes would lock real users out. If you changed your login address (see changing the WordPress login URL), use your new path as well.
Rule 2: challenge wp-admin, but not admin-ajax
(starts_with(http.request.uri.path, "/wp-admin")
and not http.request.uri.path in {"/wp-admin/admin-ajax.php" "/wp-admin/admin-post.php"}
and ip.src ne 203.0.113.10)Action: Managed Challenge. The exceptions matter. admin-ajax.php and admin-post.php are used by public features such as forms, search filters, cart fragments and many plugins on the front end. Challenging them breaks those features for visitors. This rule protects only the admin screens, so keep strong passwords and two-factor login.
Rule 3: restrict xmlrpc.php
xmlrpc.php is an old remote-access endpoint that attackers use for password guessing and amplification. Most sites do not need it. Some tools do: the Jetpack service, the WordPress mobile app and some publishing clients. If you use none of them, block it:
(http.request.uri.path eq "/xmlrpc.php")Action: Block. If you use Jetpack, either skip this rule and disable XML-RPC through a plugin, or use an allowlist of Jetpack's published IP ranges in the expression, as in and not ip.src in {...}, filled from Jetpack's current list. Do not rely on an ASN number from an old tutorial, and check that Jetpack still connects afterwards.
Rule 4: block PHP files in the uploads folder
Uploads should hold images and documents, not code. Attackers who exploit an upload flaw often place a PHP file there.
(starts_with(http.request.uri.path, "/wp-content/uploads/") and http.request.uri.path.extension eq "php")Action: Block. This is a safe pattern for nearly every site, but some old plugins store PHP in uploads, so test after adding it. A server-level rule that stops PHP running in uploads is stronger, since Cloudflare is not in front of requests that reach your origin directly. Avoid advice that blocks all .php files in wp-includes or wp-content, because plugins and themes have legitimate PHP endpoints.
Rule 5: do not cache admin or logged-in pages
Cloudflare does not cache HTML pages by default, so this matters when you have enabled "Cache Everything" or a plugin that does. Create a Cache Rule (Caching, Cache Rules):
- Expression:
starts_with(http.request.uri.path, "/wp-admin") or http.request.uri.path eq "/wp-login.php" or http.cookie contains "wordpress_logged_in" - Action: Bypass cache.
If you use WooCommerce, also bypass cache for cart, checkout and account pages, and for requests with woocommerce_items_in_cart. Caching those pages shows one customer another's data.
What about the threat score rule?
Older guides recommended challenging visitors by Cloudflare's threat score. That field has been deprecated in favour of bot and WAF signals, so do not build on it. Cloudflare's managed rules and bot features, where your plan includes them, do the same job with less manual tuning. Rate limiting for /wp-login.php, for instance five attempts a minute per IP, is an effective addition if your plan allows it.
What else protects the origin?
Cloudflare protects only traffic that goes through it. If attackers find your server's IP address, they can bypass every rule above.
Allow web traffic to the server only from Cloudflare's published IP ranges, and restore real visitor addresses with our guide to restoring the visitor IP behind Cloudflare.
Disable PHP execution in
wp-content/uploadsat the web server.Keep WordPress, plugins and themes updated, and remove those you do not use.
Use two-factor authentication on admin accounts.
You can also block noisy crawlers such as PetalBot with the same WAF tools.
How do I test and maintain the rules?
Open a private window and load
/wp-login.php. You should see a brief challenge or the login form.Submit a front-end form and a search filter to confirm AJAX still works.
Request
/xmlrpc.php, and a test PHP file in uploads (only on staging, deleted afterwards), to confirm they are blocked.Review Security, Events for blocked or challenged requests and look for false positives.
Name each rule clearly, note why it exists and the date, and review them every few months. Re-test after changing your login URL, adding a plugin that uses new AJAX endpoints, or moving host. Write the configuration down so you can rebuild it if an account change wipes it.
What can go wrong with each rule?
| Rule | Risk | Safeguard |
|---|---|---|
| Login challenge | Locks out you or your team | Exception for your own IP, and use Managed Challenge, not Block |
| wp-admin challenge | Breaks forms, search filters and cart fragments | Exclude admin-ajax.php and admin-post.php |
| xmlrpc block | Breaks Jetpack, the mobile app or publishing tools | Check you use none, or allowlist Jetpack's published ranges |
| PHP in uploads block | Breaks a plugin that stores PHP there | Test the site after adding it |
| Cache bypass | Admin or customer pages served from cache | Bypass for admin, login and logged-in cookie; WooCommerce pages too |
An engineer can configure and verify them without locking you out.
Will these rules lock me out of my own site?
They can if written carelessly. Add an exception for your own IP address, test in a private window and keep a way to disable the rule from your Cloudflare account.
Link to this answerDo these rules replace a security plugin?
No. Cloudflare filters traffic before it reaches the server. You still need updates, strong passwords, two-factor authentication and a clean site.
Link to this answerHow many custom rules does the free plan allow?
Cloudflare limits the number of rules per plan and changes the limits over time, so check the Security, WAF page of your account before planning rules. Combine conditions in one rule if you are short of slots.
Link to this answerWhy use Managed Challenge instead of Block for the login page?
A Managed Challenge lets real browsers through with little or no friction and stops simple bots. Block would lock out real users if the rule has a mistake.
Link to this answerWhy must admin-ajax.php be excluded from the wp-admin rule?
admin-ajax.php and admin-post.php are used by public features such as forms, search filters and cart fragments. Challenging them breaks those features for visitors.
Link to this answerShould I block xmlrpc.php?
Most sites do not need it, and attackers use it for password guessing. Some tools do need it, such as the Jetpack service, the WordPress mobile app and some publishing clients, so check before blocking.
Link to this answerIs blocking PHP in uploads safe?
It is a safe pattern for nearly every site because uploads should hold images and documents, not code. Some old plugins store PHP there, so test the site after adding the rule.
Link to this answerWhy do I need to bypass cache for admin pages?
If you enabled Cache Everything or a plugin that does, admin and logged-in pages could be cached. On WooCommerce, caching cart and account pages can show one customer another's data.
Link to this answerCan attackers bypass Cloudflare?
Yes, if they find your server's IP address. Allow web traffic to the origin only from Cloudflare's published IP ranges, and disable PHP execution in uploads at the web server.
Link to this answerIs the threat score rule still recommended?
No. That field has been deprecated in favour of bot and WAF signals. Use managed rules and bot features where your plan includes them, and consider rate limiting for the login path.
Link to this answerHow do I test the rules?
Load wp-login.php in a private window, submit a front-end form and search filter, confirm xmlrpc.php is blocked, and review Security, Events for false positives.
Link to this answerWhat if my site is already hacked?
Rules will not clean an existing infection. Use the WordPress security service, or call emergency support, which is pay-only-if-fixed. Cloudflare rules are a prevention layer, not a clean-up tool.
Link to this answerKeep reading
Want an engineer on it?
Tell us what is wrong in plain words. A person reads it, today.