Block bad IP addresses from accessing your website with .htaccess

No comments
If you want to block a bad IP address from accessing your website, and you have the IP address, host name or you know ISP of the visitor then you can easily block the visitor accessing your website with .htaaccess file. You can even secure a part of the website from accessing by placing a .htaccess file in the folder and the code into it.

A small tips: If you have WordPress website in which you want placing your code to block users then i would recommend that always place code after or before # BEGIN WordPress  and # END WordPress lines.

htaccess code to ban an IP


To ban a single IP place the below code into your .htaccess file and upload it to the root folder on your server.
order allow,deny
deny from 106.223.197.90
allow from all

In above example, I have blocked this IP to accessing my website and now this IP cannot visit any part of my website. However, in future if I want to give this IP acccess again, then I can remove the line from my htaccess and the IP can access the website again. The syntax to block a visitor is deny from the IP/ISP.


How to ban multiple IP addresses?

If you want to ban multiple IPs from accessing your website then also the syntax is same and you will need to add them in new line as below:
order allow,deny
deny from 106.223.197.90
deny from 106.223.197.91
deny from 106.223.197.92
allow from all

Ban a range of IPs

If you want to ban a full range of  IPs for example 106.223.197.1 to 106.223.197.225, you can easily ban as below:
order allow,deny
deny from 106.223.197.
allow from all

Ban an ISP in htaccess

Blocking an ISP is same as blocking an IP, you will need to replace the IP with the ISP. See example:

order allow,deny
deny from airtel.com
allow from all

No comments :

Post a Comment