Apr

14

From time to time, you may ask yourself: 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!



Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. mediafrenzy on May 2, 2008 11:52 am

    htaccess is really cool!

Sponsors




Links