.htaccess is a resourceful file that can allow or deny access to your website or a folder or files in the directory in which it is placed by using order, allow and deny keywords.
How to allow access to a single IP address using .htaccess
In the following example, we will assume that you want to allow access only to 188.8.131.52 IP address. The code that you will need to add in your .htaccess file is:
# Order Allow, Deny Deny from All Allow from 184.108.40.206
Order keyword here specifies the order in which allow, deny access would be processed. For the above ‘Order’ statement, the Allow statements would be processed first and then the deny statements would be processed.
How to deny access to a single IP Address using .htaccess
Let’s assume that you wish to deny or block access to your website for 220.127.116.11 IP address.
The below lines provide the means to allow access of the website to all the users accept one with IP Address: 18.104.22.168
# Order Allow, Deny Deny from 22.214.171.124 Deny from 126.96.36.199 Allow from All
# Order Deny, Allow Deny from 188.8.131.52 Deny from 184.108.40.206
If there are multiple IP’s to which you want to deny access, simply add as many ‘Deny from’ rules as needed.
That’s it. Now you know how to Allow or Deny access to your website using .htaccess.