How to Harden Your WordPress Site: Protect debug.log, Block xmlrpc.php & Stop Bad Bots

WordPress is the most popular content management system in the world, powering millions of blogs and business sites. With popularity comes risk — hackers and automated bots constantly target vulnerabilities in WordPress. That’s why securing your site is essential.

In this post, we’ll explain three powerful WordPress security techniques using simple `.htaccess` rules:

  • Protecting your debug.log file
  • Blocking access to xmlrpc.php
  • Redirecting bad bots from wp-login.php

Why WordPress Needs Security

WordPress sites are often targeted because:

  • They use the same default files and structure
  • Many sites run outdated plugins or themes
  • Login pages are exposed to brute force attacks

Using simple security rules in your `.htaccess` file can block unwanted traffic and protect sensitive files.

Protect the debug.log File

When WordPress debugging is enabled, it can create a debug.log file that may contain paths and error messages — potentially exposing sensitive data. To block public access, add this rule:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?wp\-content/+debug\.log$
RewriteRule .* - [F,L,NC]
</IfModule>

<IfModule !mod_rewrite.c>
<Files "debug.log">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
</IfModule>

This stops anyone from accessing debug logs directly and leaking internal server information.

Block xmlrpc.php to Prevent Abuse

The file xmlrpc.php is used for remote publishing and some plugin features, but it’s also a frequent target for brute force attacks. Blocking it can significantly reduce unauthorized login attempts:

<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>

This rule blocks all external access to XML‑RPC functionality if your site doesn’t need it. Most modern sites don’t.

Redirect Bad Bots from wp-login.php

Automated tools like curl and wget are commonly used by attackers to target wp-login.php. To redirect these bad bots away from your login page, use this rule:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/wp-login\.php$ [NC]
RewriteCond %{HTTP_USER_AGENT} (wget|curl) [NC]
RewriteRule .* / [R=302,L]
</IfModule>

This redirects bots to your homepage, stopping automated login attempts before they start.

Additional WordPress Security Tips

  • Keep WordPress core, themes, and plugins updated
  • Use strong passwords and two‑factor authentication
  • Install a reputable security plugin
  • Regularly back up your site

Conclusion

Security doesn’t have to be complicated. By protecting sensitive files like debug.log, blocking access to xmlrpc.php, and filtering bad bots from wp-login.php with simple `.htaccess` rules, you can significantly improve your WordPress site’s defense.

Implement these WordPress security rules today and keep your site safe from common threats!

Need Professional WordPress Security Help?

If you want expert help securing your WordPress website, fixing vulnerabilities, or setting up advanced protection, our team can help.

👉 Contact CodeNBrand for Professional WordPress Security Services

About Author

Shiva Sheshendra

Senior Web Developer / Senior PHP Developer / Full Stack Developer

“Web Development, Website Maintenance, Server Management, On-Page SEO, Security, and Malware Removal”

Connect with Developer View Portfolio

Request A Callback

Have a Development Requirement?
Share your requirements and we’ll help you plan the right technical solution.

© All rights reserved 2026 codenbrand. Designed and Developed by shivafeb17

WhatsApp Icon