Locking Down a Site via htaccess Print

  • 27

More than likely, you've been faced with one of two scenarious:
  • You need to block all access to an internal website, allowing only certain IP addresses
    OR
  • You need to block certain IP addresses from connecting


If you see your self needing to lock down a private website allowing only certain IP addresses to connect, you can use htaccess for this.

You can do the following to lock down a given directory on your server, giving a forbidden HTML code when non-whitelisted IPs try to access the site:

  1. Login to your server via SSH
  2. Goto the website directory that you are wanting to lock down - e.g. /home/user1/public_html/admin_interface/
  3. Create a new file in that directory - or edit the existing - file with the name of .htaccess
  4. Put the following at the top of the file:

    order deny,allow
    deny from all
    allow from 127.0.0.1
    allow from IP1
    allow from IP2
    ...
  5. Save and quit the file


With the .htaccess file having the above contents at the top, your sites admin_interface page will now be locked down to IP1 and IP2
* 127.0.0.1 is the loopback address of your server and is usefull for testing and other functionality


Was this answer helpful?

« Back