How To Block IP Address Using .htaccess method

Block IP Address using htaccess
  • Save

We have already covered some interesting topics on wordpress .htaccess hacks.

This post can be used for wordpress or for any website, by editing your .htaccess file. If you are not familiar with .htaccess file, refer to above mentioned post or get in touch with your hosting CC.

If you are receiving Spam comments and other such activities from some person at a specific IP address, then you can easily deny access to your site by creating .htaccess file with the below mentioned code in it.

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

First identify the IP address of that visitor. There are two methods for this (I prefer these) :

  • 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 finding the IP addresses.

Create .htaccess file and type the following code in it.

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

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

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

It is used mostly when your blog is under construction and you don’t want your readers to see the site until it is over or even search engine spiders indexing problems.

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

Note that   each IP address is placed on a new line.

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

Replace the given IP address with your desired IP address.

If you like this post and find it to be informative, don’t forget to tweet it.

Was this helpful?

Thanks for your feedback!
  • Save
Authored By
A simple kid next door of yours ! :)

2 thoughts on “How To Block IP Address Using .htaccess method”

  1. jaganmangat

    hey thanks for this post pradeep ,i was searching for this and got it……

  2. Robin

    Generally i use .htaccess to restrict folder access to certain ip addresses. its a great tool.

Leave a Comment

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

Scroll to Top