Locking Down a Site via htaccess

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

  • 27 Users Found This Useful
Was this answer helpful?

Related Articles

Adding Additional Modules to PHP via WHM

Additional modules can be added to PHP via the WHM control panel. Below are instructions on how...

Video Tutorial: Create Hosting Account in WHM

Please do not hesitate to contact us if you need any further assistance.

cPanel: How to Clear Brute Force Logs via SSH

Login into your VPS via SSH and enter: echo "delete from brutes; delete from logins;" | mysql...

Video Tutorial: Managing DNS Zones in WHM

Please do not hesitate to contact us if you need any further assistance.

Video Tutorial: What is the difference between WebHost Manager (WHM) and cPanel

Please do not hesitate to contact us if you need any further assistance.