How to allow or deny ip addresses using .htaccess

The file .htaccess always comes useful whenever we need more protection for our website. Among all the capabilities of .htaccess we are here going to discuss it capability of allowing or denying IP address. I need this function because there are some directories on my server which are critical to my business and hence want to protect these from evil eyes.

Let us say you have a directory HOME which you want to protect. Just follow the instructions given below to protect the given directory:

  1. First of all create a new file in the given directory and name it as .htaccess
  2. Open this file in any editor.
  3. Write this line the newly created file deny from all
  4. After than write allow from xxx.yyy.zzz.qqq
  5. In the above statement xxx.yyy.zzz.qqq is the IP address which you want to allow
  6. In case you want to allow a range IP address than simply leave the block which is dynamic or variable in your ip address. For eg.
  7. allow from xxx.yyy
  8. In case you just want to deny just one IP address, than simply write deny from xxx.yyy.zzz.qqq

Though this method is perfect for blocking  individual ip addresses but it is not efficient enough to block a particular range of IP address. By efficient i mean that we cannot make a particular range of IP address to block using this method