Block IP from accessing website using .htaccess

To block certain ip address from accessing your website, just create a file with name .htaccess at your root directory with the content below:-

order allow,deny
deny from 192.168.0.1
allow from all

If you want to block multiple ip address using .htaccess simply add one ip address per line as below:-

order allow,deny
deny from 192.168.0.2
deny from 192.168.0.3
deny from 192.168.0.4
allow from all

You can even block a network range ip using .htaccess:-

order allow,deny
deny from 129.0.0
allow from all

Note: .htaccess only works in apache webserver, if you do not know what web server you are on, your can consult with your server administrator for more details.

Technorati Tags: , , , , , , , ,

Share and Enjoy:
  • Reddit
  • BlinkList
  • del.icio.us
  • Digg
  • Fark
  • IndianPad
  • StumbleUpon
  • YahooMyWeb
Posted at January 10th, 2007 by chua

If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)

Related Post

2 Responses to “Block IP from accessing website using .htaccess”

  1. Jeremy Says:

    Another kind of cool thing to do is block say the whole 8 bit like
    deny from 41.0.0.0/8

    Which would block all 41.0.0.1 thru 41.255.255.255 all in one pop. Sometimes this is too much, but it is handy for blocking entire countries or areas on occassion.

    Then if there was one like 41.25.85.35 you wanted to allow:
    deny from 41.0.0.0/8
    allow from 41.25.85.35

    Sometimes it’s easier to deny a whole bunch and allow only a few than to type a couple hundred (one per line).

    Jeremy
    dialme.com

  2. Mouze Says:

    You can also ban everyone except for your home IP address like so:
    order deny,allow
    allow from YOURIPADDRESSHERE
    deny from all

Leave a Reply