Liked the Blog?? Subscribe to NiharsWorld RSS Feed
Powered by MaxBlogPress  


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 favourite 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 120.120.120.120. I will add the below entry in .htaccess at the end of the file.
    deny from 120.120.120.120
  • 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!

Technorati Tags: ,



2123 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:




You Should Also Check Out These Posts:


41 Comments

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

    Blogspot to wordpresss last blog post..MaxBlogpress Ping optimizer : WordPress must have plugin

  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

    Atuls last blog post..Sachin Tendulkar-GOD of Cricket

  5. TechZoomIn says:

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

    TechZoomIns last blog post..Winsyntax: Simple & Free PHP Editor..!

  6. venkat says:

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

    venkats last blog post..Get TechSmith Snagit 7.25 absolutely FREE

  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!

    Donaces last blog post..Beware the smiling man

  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…

    Ajith Edasserys last blog post..Blog Statistics: What, when and where?

  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

    Atuls last blog post..Sachin Tendulkar-GOD of Cricket

  10. venkat says:

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

    venkats last blog post..Subscribe to our Blog and get Freebies straight to your Inbox

  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

    Atuls last blog post..Sachin Tendulkar-GOD of Cricket

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

  13. [...] How to avoid Hotlinking of file and images using .htaccess hack Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Yesterday, i posted a .htaccess hack to Block Visitors from specific IP using .htaccess [...]

  14. Samrat P says:

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

    Samrat Ps last blog post..Create Online Presentations With Adobe

  15. [...] How to Block Visitors from specific IP using .htaccess hack [...]

  16. [...] Few days back, Atul from Ocean of Web left a comment at How to Block Visitors from specific IP using .htaccess hack. [...]

  17. Neeraj Kumar says:

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

Leave a Reply