How to block IP address using .htaccess
The simple solution to it is to block IP address using .htaccess file. It will restrict the user of that IP from accessing your website.
All you have to do is put a specific code in your .htaccess file, then the .htaccess file will deny all the requests generated from that specific IP address.
How to deny access to an IP address using .htaccess method
First you have to get the IP Address that you want to block, hen head to the .htaccess file and insert the below code to restrict the IP address.
<Limit Get Post> order allow,deny allow from all deny from xx.xx.xx.xx </Limit>
While inserting your code to your .htaccess file you should replace xx.xx.xx.xx with the IP you like to block, If you like to block more than one IP the insert another “deny from xx.xx.xx.xx” below the first one.
There are ways by which you can use IP addresses to allow or deny requests.
Tip: You can allow are deny the IP address with some variations too. The basic structure of IP is “xx.xx.xx.xx” there these xx range from 0-255. You can use the below combination for an addition functionality with IP addresses.
- 18.104.22.168 Blocks a specific IP
- 1.2.3. Blocks IP from the range 22.214.171.124 to 126.96.36.199
- 1.2. Blocks IP from 1.2.xx.xx
- 1.2 Blocks IP from 1.2x.xx.xx
You can use these for blocking a single IP to a full range. There is a way by which you can allow only selected IPs, this can be useful if you are making changes to your blog like a new blog design and don’t want anyone to access it till you are finished. This code will allow only you and the IP addresses you want to access your website.
<Limit Get Post> order deny,allow deny from all allow from xx.xx.xx.xx allow from xx.xx.xx.xx </Limit>
If you want to add another IP then just simply add another “allow from xx.xx.xx.xx” , remember to replace xx.xx.xx.xx with the IP you want to allow.