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.
Tags: .htaccess, .htaccess block access, .htaccess block ip, .htaccess block ip range, apache, apache .htaccess, block access, block access to website, block ip
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 :)


June 3rd, 2008 at 4:58 pm
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
July 4th, 2008 at 6:18 am
You can also ban everyone except for your home IP address like so:
order deny,allow
allow from YOURIPADDRESSHERE
deny from all
August 28th, 2008 at 9:52 am
[...] 参考网址: http://www.techiecorner.com/95/block-ip-from-accessing-website-using-htaccess/ [...]
February 14th, 2009 at 12:40 pm
Is there a way to block just specific URLs from an IP range, something like the RewriteRule 301 statements?
It would be something like:
for the following URLs/regular expressions
deny access to this IP range
February 14th, 2009 at 1:36 pm
Hi, please help someone.
Somehow, someone has manually blocked my IP address (mine only) from accessing all of my personal websites. This is most probably a personal attack and I know who did it too. They have done this from the other side of the world.
They even blocked my ip from accessing lunarpages which is the people he knew I would go to for help.
PLEASE can someone tell me:
1) How did they do it without having access to my ftp logins or my office/computers?
2) How do I undo it
FYI, I can access my sites when I hide my IP address and No one has touched my computers settings.
Please tell me what this problem is and how to fix it. Big respect to anyone who can solve this riddle.
Regards,
Daniel
September 23rd, 2009 at 1:46 pm
Daniel, did you ever get a fix/answer to this? Good luck.
October 1st, 2009 at 3:30 am
Daniel:
You should have emails with contact phone numbers from Lunar pages. If this is true, you should be able to call them, provide something like a billing credit card number, and then have them manually check your .htaccess files for any sign of IP additions like above.
Also, you are POSITIVE it’s an IP attack like that? For example, you can access your sites from any other location except for your own home? Also: you’re receiving a static IP from your provider, and not a dynamic one? It just seems like a really weird issue.
Good luck!
January 30th, 2010 at 12:02 am
Where can I create the .htaccess file? in which path?
February 1st, 2010 at 10:33 am
at the document root path. If u r using CPanel, here’s the patch to your .htaccess
/home/acname/public_html/.htaccess