How to restrict Directory Access by IP address

Á

Álvaro Moura

Last updated on Jul 6, 2026

In order to secure your "admin area" from hackers, we recommended you to allow access only from your selected IP to your admin directory. You just need to create an .htaccess file in the directory where you want to restrict access by IP Address.

For example, if you have a WordPress blog installed on your main directory like example.com/wp-admin, you should create an .htaccess file in /wp-admin/.htaccess and you should put this code in, and not forget to replace the allowed IP address with your IP address.

  • order deny,allow
  • deny from all
  • allow from IP-ALLOWED

(Replace "Your-IP-Address-Here" text with your IP Address)

You can test this by accessing **your-domain/wp-admin,**from an IP address other than the one allowed by your .htaccess file.