Welcome, Guest. [ Log In ]
Question   How do I block people coming from a certain website or URL from visiting my site or directory?
Search KBase


Related Links:
· How do I block certain IPs from accessing my site or directory?
· Custom 403 (Forbidden) error pages.

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 people coming from a certain website or URL from visiting my site or directory?
It's actually very similar to blocking people by IP! Again, you need to add some lines to an .htaccess text file that you create in the home directory of your web site.

Here is some example code for giving everybody who comes to you from www.yahoo.com or www.google.com a 403 error (access denied):

SetEnvIfNoCase Referer "^http://www.google.com/" BadReferrer
SetEnvIfNoCase Referer "^http://www.yahoo.com/" BadReferrer
order deny,allow
deny from env=BadReferrer

Another way to block people where you end up just redirecting them to a different url involves using the "mod_rewrite" functionality of our web server. Here's how to block everybody from www.yahoo.com and www.google.com again (put this in your .htaccess file):

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://www.yahoo.com/
RewriteRule /* http://www.yoursite.com/restricted_url.html [R,L]
RewriteCond %{HTTP_REFERER} ^http://www.google.com/
RewriteRule /* http://www.yoursite.com/restricted_url.html [R,L]

We hope this helps keep those annoying people out of your site!

Last updated: Mar 14, 2005.

Official Reply (2005-03-01 15:37:03 )
Also note, you can now add this to the end of your RewriteRule if you don't want rewrites from showing up in your log file and therefore your statistics:

[E=dontlog:1]
User Post (2004-12-15 00:59:42 by achiang)
I've been noticing that most of my referrer spam comes from a .info TLD (top level domain). I can't seem to find any legitimate instances of a .info url (ie, one that's *not* spam), so I decided to just block *all* accesses from .info.

----------------------------------------------------------------------
SetEnvIfNoCase Referer ".*\.info/$" BadReferrer
order deny,allow
deny from env=BadReferrer
----------------------------------------------------------------------

More details on my blog: http://www.chizang.net/alex/blog/archives/000433.html
User Post (2004-08-09 21:07:04 by jcudmore)
Here is an excellent tutorial!

Smarter Image Hotlinking Prevention:
http://www.alistapart.com/articles/hotlinking/
User Post (2003-10-23 10:26:11 by czottmann)
If you get referrer-spammed from various sources, do the funky wildcard thang:<br /><br />

<pre>
### STOP REFERRER SPAM
SetEnvIfNoCase Referer ".*(sex|hardcore|porn|pussy|xxx|webcam|ficken|fuck).*" BadReferrer
order deny,allow
deny from env=BadReferrer
</pre>

Excuse the examples, but that's exactly what I have to deal with on my sites. If you want to add more text pieces that you want the .htaccess to check for, add a "|anotherbadword" inside the parentheses.<br /><br />

Carlo, http://G-Spotting.net