How To Block IP Address Using .htaccess method

IN WordPress

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. wordpress_logo

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.

order allow,deny
allow from all
deny from 12.345.67.890

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.

order deny,allow
deny from all
allow from 12.345.67.890

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

order deny,allow
deny from all
allow from 12.345.67.890
allow from 890.67.345.12

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.


Subscribe on Youtube

Click to activate Offer & visit site Discount added automatically
No related entires

Subscribe to SML Newsletter

Receive Blogging Tips & Strategies

Get WordPress Guide eBook for free in the 2nd newsletter

100% privacy. we will never spam you

  • Author Bio

  • Latest Post

Blog post by S.Pradeep Kumar

S.Pradeep has written 1 articles.

Follow ShoutMeLoud on Twitter. Subscribe to ShoutMeLoud feed via RSS or EMAIL to receive instant updates.

    Send Us Inquiry


    1. Robin says

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

    Leave a Reply

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

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>