Indian company. Since 2018.
Security

Restrict Directory Access by IP Address with .htaccess

15,748 genuine article views Security

Tip: if you cannot see the .htaccess file in cPanel File Manager, enable Show Hidden Files (dotfiles) in File Manager settings.

You can restrict access to a directory by allowing only specified IP addresses in its .htaccess file. This example uses Apache 2.2 access-control directives.

  1. Create or edit the .htaccess file in the directory you want to protect. For a WordPress installation, this might be wp-admin.
  2. Add the following directives, replacing the placeholder with the IP address you want to allow:
    order deny,allow
    deny from all
    allow from YOUR-IP-ADDRESS-HERE
  3. Save the file, then test access from the allowed IP and from a different IP.

Requests from IP addresses not listed in the file will be denied. These directives are for Apache 2.2; Apache 2.4 uses different access-control syntax.