.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 18.104.22.168 IP address. The code that you will need to add in your .htaccess file is:
# Order Allow, Deny Deny from All Allow from 22.214.171.124
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 from 126.96.36.199 IP address.
The below lines provide the means to allow access to your website from all users except one with the IP Address: 188.8.131.52
# Order Allow, Deny Deny from 184.108.40.206 Deny from 220.127.116.11 Allow from All
# Order Deny, Allow Deny from 18.104.22.168 Deny from 22.214.171.124
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.