.htaccess – Blocking sites by URL

  • Posted On: May 10th, 2007
  • Filed Under: Web Design
  • Tagged As:

Last week I found the need to block incoming traffic from a particular site. While the author was kind enough to remove the links to my page when I first discovered the issue I was quick to block the traffic just to be safe.

The following code can be placed in your .htaccess file to block incoming traffic by URL.

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} FirstSite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} SecondSite\.co\.uk
RewriteRule .* - [F]

The code above blocks traffic from two separate URLs. [NC, OR] should follow every line after the first but excluding the last in order to block more than one site.


One Response to “.htaccess – Blocking sites by URL”

  1. July 7th, 2008 at 12:25 pm

    I have tried this but since cPanel on my server is used to create and edit htaccess through it’s HotLink Protection feature, by adding this, I just anebled the URL’s I wanted to block, to see and hotling the pictures.

    I would however like to block a few URL’s that have links on their forums to my site.

    How do I do that? Any idea? In my case this isn’t working.

    - FrankZ