How to Block IP Address from accessing your website using .htaccess

In this tutorial we are going to discuss about a simple .htaccess trick to block user by ip address from accessing your website, You may have to face issue like that where some robot script keep pinging your website and website faces server down issue or some one forcefully reading your website pages dynamically and stealing your content, If your are facing such types of issue and you know the person IP then you can easily block those person’s ip by .htaccess tricks.



block-ip-address-htaccess

First make sure that you have created a file with name .htaccess at your root directory

To block certain ip address from accessing your website paste below rules on your .htaccess file.

order allow,deny
deny from 192.168.0.100
allow from all

Where The first line “Order allow, deny” tells the web server the “Order” in which the Allow and Deny directive will be evaluated. It simply says: Give access to all hosts that are not present in the Deny from list and are present in the Allow from list. With allow, deny order Allow list is looked up first and then the web server checks the deny from list. So as we have allow from all – all access is allowed. Then the allowed access is filtered based on the Deny lists. With allow,deny access is disabled by default.

If you want to block multiple ip address then follow below commands.

order allow,deny
deny from 192.168.0.100
deny from 192.168.0.101
deny from 192.168.0.102
deny from 192.168.0.103
allow from all




You can also block certain network range like 192.168.0.0 – 192.168.0.199

order allow,deny
deny from 192.168.0
allow from all

To block all access to your site

order allow,deny
Deny from all

And then add another line to enable access only for particular ip

order allow,deny
Deny from all
Allow from 192.168.0.100

If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Leave a Reply

Your email address will not be published. Required fields are marked *

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