Limit access to sensitive WordPress areas via .htaccess

First check if the request is for xmlrpc.php, wp-login.php or the wp-admin folder. Then see if the IP or subnet belongs to an actual administrator. If not, block the request with a 403 Forbidden (F) response and stop all further rewrite processing immediately (END).

RewriteEngine On

# Restricted paths
RewriteCond %{REQUEST_URI} (^|/)(xmlrpc|wp-login).php [NC,OR] 
RewriteCond %{REQUEST_URI} (^|/)wp-admin(/|$) [NC]

# Allowed IPs/subnets
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.1$
RewriteCond %{REMOTE_ADDR} !^127\.0\.

# Block everyone else
RewriteRule ^ – [F,END]

Leave a Reply

Your email address will not be published. Required fields are marked *