Blocking Users By Referrer

If one day you notice tons of referrals from a particular site, but realize that you don't have a single link to theirs, they may be hotlinking to certain images or files of yours. To stop this, you can use a .htaccess file, with Apache's module mod_rewrite enabled. Most servers automatically enable mod_rewrite, but if it's not, ask your host.

Block Traffic From One [Single] Referrer

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} blocksite\.com [NC]
RewriteRule .* - [F]


In this case, blocksite.com is the domain that would be blocked. When you change it, be sure to leave the "\" in front of the .com, as it triggers an escape sequence, and without it an error would occur. The [NC] makes it case insensitive, so BlockSite.com is the same as blocksite.com. The last line specifies that the request should be failed when a match is found, meaning the referrer traffic will run into a 403 Forbidden error.


Block Traffic From Multiple Referrers

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} blocksite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} anotherblocksite\.com
RewriteRule .* - [F]


This is entirely the same as blocking a single site, except this time, the [OR] is included with the [NC]. Simply copy & paste another line of code to insert more block sites.


Finally, you may have noticed that the Options +FollowSymlinks is commented out. Some sites aren't configured with FollowSymLinks in the <directory> section of httpd.conf. If you get a 500 Internal Server Error when you upload the file, uncomment the line and all should be well. Hope this helps! =)


[Back]


Custom Search


Choose Your Skin:

Site
 
Designs
 
Graphics
 
Scripts/Reads
 
Tutorials
 
Affiliates
 
Other
 
Skins
 
eXTReMe Tracker