How To Block IP Address Using .htaccess File

Wordpress Development Company

Follow this post for WordPress or any other website using other cms or framework, by editing your .htaccess file. If you are not familiar with .htaccess file, you can read about it or get in touch with your hosting company.

If you are getting Spam comments and other spamming activities by some location or from some person at a particular IP address, then you can easily block access to your site by creating .htaccess file with the following mentioned code in it.

How To deny IP access to your Website using .htaccess File:

First find the IP address of that visitor. There are two methods for this:

-If that visitor already commented in your blog, then you can find that person’s IP address easily from your WP dashboard.
-Use StatCounter for searching the IP addresses.

Create .htaccess file and write below code in it.

< Limit GET POST PUT>
order allow,deny
allow from all
deny from 123.298.88.342
< /Limit>

Here is 123.298.88.342 is the IP address of the person you want to block. You can replace this with your site visitor IP address. You can allow Visitors From Specific IP Address Using .htaccess

By this code in your .htaccess file, you can easily block access to your website from every IP addresses except the IP addresses you specified in the code.

It is used mainly when your website is under construction and you don’t want your visitors to see the website until it is complete or even search engine indexing problems.

< Limit GET POST PUT>
order deny,allow
deny from all
allow from 123.298.88.342
< /Limit>

Please note that every IP address should be placed on a new line.

< Limit GET POST PUT>
order deny,allow
deny from all
allow from 123.298.88.342
allow from 345.76.321.98
< /Limit>

Replace the given IP address with your visitors IP address.