Community Support
January 09, 2009, 09:12:06 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Staff List Login Register  
Pages: [1]
  Print  
Author Topic: .htaccess Banning  (Read 26 times)
Andrew
Byteact/i.create Administrator
Administrator
*****
Offline Offline

Hosting Plan: Premium Hosting
Operating System: Linux
Browser: Opera
Posts: 127
Referrals: 2



« on: June 19, 2008, 11:56:47 AM »

User IP Banning

Have a troublesome user who just keeps coming back again and again to cause your community grief? Why not ban them via .htaccess!

Code:
## USER IP BANNING
<Limit GET POST>
 order allow,deny
 deny from 42.12.5.34
 deny from 212.173.53.
 deny from 69.242.
 deny from .aol.com
 allow from all
</Limit>

So, what does each one do?

 deny from 42.12.5.34 blocks a specific IP address
 deny from 212.173.53. blocks all IPs in the 212.173.53.xxx range
 deny from 69.242. blocks all IPs in the 69.242.xxx.xxx range
 deny from .aol.com blocks everyone from aol.com

Bad Site Banning

But what if you want to ban an entire website from your website, say because they're spamming your statistics or they're just downright bad for some reason.

Not a problem...

Code:
## SITE REFERRER BANNING
RewriteEngine on
# Options +FollowSymlinks

RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} badsite\. [NC,OR]
RewriteCond %{HTTP_REFERER} sub\.badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} 32\.173\.21\.187 [NC]
RewriteRule .* - [F]

How's it work?

RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR] bans all traffic with badsite.com in the referring URL
RewriteCond %{HTTP_REFERER} badsite\. [NC,OR] bans all traffic with badsite.xxx in the referring URL (covers all TLDs)
RewriteCond %{HTTP_REFERER} sub\.badsite\.com [NC,OR] bans all traffic with sub\.badsite\.com in the referring URL
RewriteCond %{HTTP_REFERER} 32\.173\.21\.187 [NC] bans all traffic with 32.173.21.187 as their referrer

Hotlinking Prevention

But what if you're just wanting to save your bandwidth and prevent people from hotlinking your images? Got you covered...

Code:
## DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sub.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?24.56.32.125/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|png|js|css)$ - [F]
# RewriteRule .(gif|jpg|jpeg|png)$ http://www.example.com/images/stealing.gif [R,L]

In short, this one allows gif, jpg, jpeg, png, js and css files to be hotlinked from example.com, sub.example.com and 24.56.32.125 while blocking them from the rest of the world

The last line is optional, basically allows you to serve up whatever image you want when someone links one of your images, to use it uncomment it.
Logged

Unsolicited private messages for support issues will go unanswered
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC | Sitemap | Archive Valid XHTML 1.0! Valid CSS!