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.
- Create or edit the
.htaccessfile in the directory you want to protect. For a WordPress installation, this might bewp-admin. - 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 - 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.
