Welcome, Guest. [ Log In ]
Question   How do I block certain IPs from accessing my site or directory?
Search KBase


Top 5 in this Area:
1. How do I use .htaccess files?
2. How can I turn off the default directory listing in a directory?
3. How do I block people coming from a certain website or URL from visiting my site or directory?
4. Can I use .htaccess files?
5. How do I stop "hotlinking" to my files?

 
How do I block certain IPs from accessing my site or directory?
It's pretty easy!

All you have to do is create an .htaccess file in the directory you'd like to restrict (your main directory to restrict the entire site) and then put the following in it:

<Limit GET>
order allow,deny
allow from all
deny from 123.142.124.152
deny from 124.24.
</LIMIT>

You can put whole ips or just the beginning part you'd like to match, and you can add more and more ips, each with its own line!

When somebody's ip is banned, they will get a 403 error (access forbidden) when trying to visit your site.

Last updated: Oct 29, 2002.

User Post (2005-11-14 22:58:26 by binaryeric)
Does anyone know if this is a problem? (The last part of the message)

Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Thanks,
Eric
User Post (2005-05-28 20:17:33 by d0llhaus)
Does anyone know how I can block everything BUT the forbidden.html file so that the blocked user sees my custom 403?
User Post (2005-04-27 16:33:22 by nov7dev)
# 123.456.789.44 - 123.456.789.60
RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.([4][4-9])$ [OR]
RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.([5][\d])$ [OR]
RewriteCond %{REMOTE_ADDR} 123.456.789.60

# 123.456.789.44 - 123.456.789.69
RewriteCond %{REMOTE_ADDR} ^123\.456\.789\.([4-6][\d])$

# 123.456.789.0 - 123.456.789.255
RewriteCond %{REMOTE_ADDR} ^123\.456\.789.*$

# 192.168.1.0 - 192.168.1.7
RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.[0-7]$

http://www.webmasterjoint.com/articles/0902/rewrite_rules_1.php
http://www.regular-expressions.info/examples.html
http://www.regular-expressions.info
User Post (2003-08-30 12:29:10 by corecom)
Is there any way to just block a group of IP's without blocking the entire 0-255 range? For example 123.456.789.44 - 123.456.789.60
User Post (2003-08-20 07:28:41 by josephgrossberg)
also, please note that there's no space between the comma and the second word -- i.e. it's "allow,deny" not "allow, deny" -- putting a space there will mess it up.
User Post (2003-08-20 06:26:58 by josephgrossberg)
mirla:

Only if your IP address is 123.142.124.152 or in the 124.24.* range
User Post (2003-02-03 22:29:14 by mirla)
Won't the above example deny me access to my own directory as well?
User Post (2003-01-08 09:55:56 by redbeard)
If you want to remove all access to a directory, try
<pre>&lt;Limit GET&gt;
order deny,allow
deny from all
&lt;/Limit&gt;</pre>