Htaccess to block ip

Websites are naturally geeks guinea pig . You will get much more spam if you get a website to comment or something . They just don’t stop . Try and try . You will find it very much annoying . You can pause them . Not stop but it will give you peace i think . Now open any text editor and

block_ip_htaccess

Type codes from below .

order allow,deny
deny from 127.0.0.2
deny from 127.0.0.1
allow from all

Now put your desired ip or ips . each in new line by that pattern . You can use 58.97.*.* to block the next ips . And save that file by .htaccess . upload that file in your websites root , maybe /public_html/  . If you have a .htaccess , then edit that file and put above codes after all codes in your .htaccess after existed codes .

Now let you want to allow a particular page or file to accessed by only a particular IP or IP range and Deny access for all other users or visitors, You have to put below codes in htaccess.

<Files login.php>
order allow,deny
deny from 127.0.0.2
deny from 127.0.0.1
deny from 127.0.*.*
allow from 192.168.23.7
allow from all
</Files>

*to allow

Now if you want deny for a particular folder then just open a htaccess file to that fodler by having this code :

order allow,deny
deny from 127.0.*.*
allow from 192.168.23.7
deny from all

So now by above code you will only be allowed to access the folder by 192.168.23.7 and deny from all other IP. Change according to yours.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.