How to restrict access to wp-admin by IP Address

One of the easiest and quickest way to protect your WordPress admin is to use an .htaccess file to restrict access to a certain IP. To do this use the following code:

In your /wp-admin folder, add an .htaccess file with the following in it:


Order deny,allow
Deny from all
Allow from xx.xx.xx.xx
#range would be
#Allow from xx.xx.xx.0/24
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>

Obviously, replace xx.xx.xx.xx with your current IP address.

The <Files admin-ajax.php> block allows access to the WP ajax hooks that are contained within the wp-admin folder. This rule allows access to this file.

To do the same to the wp-login.php file (which is the gateway to wp-admin), use the following code in the .htaccess file in the root of your site:


<Files wp-login.php>
Order deny,allow
Deny from all
Allow from xx.xx.xx.0/24
#Another IP
Allow from xx.xx.xx.xx
</Files>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s