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:
- First of all create a new file in the given directory and name it as .htaccess
- Open this file in any editor.
- Write this line the newly created file deny from all
- After than write allow from xxx.yyy.zzz.qqq
- In the above statement xxx.yyy.zzz.qqq is the IP address which you want to allow
- 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.
- allow from xxx.yyy
- 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