• Blogging
  • Freebies
  • Freeware
  • How-To
  • Make Money Online
  • Mobile
  • Home >> How-To >> How to Block Visitors from specific IP using .htaccess hack

    How to Block Visitors from specific IP using .htaccess hack

    I am sure most of the Website owners or Blog owners have faced this problem. Some visitor is nasty or jealous and wants to trouble by posting abusive comments or do harm to the website.

    One of the solutions is to Block or Deny the access to your Blog or website.

    Yes, you can block a Visitor of your website. Read on to know how to do that….

    Block Visitor from Specific IP Address using .htaccess Hack

    I am assuming that you know about .htaccess file. It resides in the root directory of your website. The root directory could be /www/, /httpdocs/ or /public_html/ directories. Any of them depends on the hosting service.

    Make sure you backup .htaccess file before you making any changes.

    • Grab the IP Address of that visitor by checking your favorite Stats webservice. I use StatCounter to get the IP Address or WordPress Dashboard (if the visitor has left a comment).
    • Login to your hosting service site and open code>.htaccess file. Make sure you backup the file before making any changes.
    • Lets say i want to block a Visitor coming from this IP Address I will add the below entry in .htaccess at the end of the file.
      deny from
    • Now save the file

    If you want to block more visitors, just keep adding the ip addresses in .htaccess file .

    In this way, you can also block the automated spammer.

    If you know any other way, please share via comments. Hope you learned something from this post!

    IMPORTANT: This blog welcomes Guest Bloggers, Writers to also contribute by writing Guest Posts and also Make Money!. Check out our Revenue Sharing Program
    1924 readers are already subscribed to this blog! Why don't you be one of them? Subscribe to this blog via your favorite RSS feed reader or by entering your email address on the form below:


    1. This is very useful Nihar specially to block those spam comments and spam bots joining my blog…

    2. Ricky says:

      Good to see you on new theme.I have tried this method to block some spammers.
      One more request why don’t you mobilize your website buddy.

    3. Pallab says:

      I actually was using a wpress plugin briefly that automatically added ip addresses of spambots to htaccess list. But soon the htaaccess file got really bloated. Stopped using that when I found a better antispam software.

    4. Atul says:

      Hi Nihar
      I have a query. for a single post, u post it in 2-3 categories. Doesn’t google count it as Duplicate

    5. TechZoomIn says:

      Much needed information for me. Thanks a lot Nihar…I’ll try and ask you if any doubts.

    6. venkat says:

      does there any facility to block ip addresses like this for blogspot blogs .

    7. Donace says:

      Nice trick Nihar but it can lead to your htaccess file getting a bit bloated so not recommended.

      BTW check out my latest post for another anti-spam hack!

    8. The only problem with this approach is that sometimes when you block an IP on a shared host, the trackbacks from other potential blogs on that IP could get banned? I am not sure… Usually, there are 600 or 700 domains on a single IP of those shared hosting services.

      And as Donace said, the htaccess file can really grow in no time…

    9. Atul says:

      Hi Nihar

      Instead of this, I recommend any wordpress plugin like Aksimet, Wp-Spamfree etc. Me personally using Wp-Spamfree for my blog

    10. venkat says:

      I am thinking to take a domain and move to wordpress in future .

    11. Atul says:

      Hi Nihar
      Make sure you backup .htaccess file before you making any changes.

      for this line in red color box with cross mark, are u using any plugin for this

    12. Than you for this hack, I’ve been wondering how to block some spammers from one of my blogs

    13. Samrat P says:

      This is a good way to stop spammers… But sometimes I love to read the spam comments.. bit funny!!

    14. Neeraj Kumar says:

      Good info ! Can use it as i am having trouble with some spammers recently.

    15. jessi says:

      i am using wp-ban for same purpose plugin ,very simple to use plugin ….thanx for sharing your knowledge..

    16. asutempek bosok says:

      eeeeeeeetttttteeeeeeeeeelllllllll ggggggggggaaaaaaaaaarrrrrrriiiiiiiiiiinnnnnnnnnnnnnggggggggg

    Leave a Reply

    page counter
    NiharsWorld on Twitter NiharsWorld on Facebook NiharsWorld RSS Feed