Blocking Content by Referer

Friday, October 10. 2008

As I already wrote I am tired of people that use my images on their sites and consuming my bandwidth. Don't get me wrong. I always appreciate links to my site and I am pleased if you find something useful. What I don't like however is that someone refers to high resolution images as background images for his site that are meant as desktop wallpapers.

A colleague gave me the hint to block this sites by the referer through .htaccess files in the respective directories. And this works great for me:


RewriteEngine on
RewriteCond %{HTTP_REFERER} .taringa\.net [NC]
RewriteCond %{HTTP_REFERER}
.myspace\.com [NC]
RewriteCond %{HTTP_REFERER} .blogger\.com [NC]
RewriteCond %{HTTP_REFERER}
.blogspot\.com [NC]
RewriteRule .* - [F]

Essentially that blocks embedding content from my site into theirs. The Apache web server needs to have support for .htaccess files as well as the module mod_rewrite, but most servers have this by default. So this should not be a big problem.

The first lines makes sure that the rewrite engine is activated. The next four lines are blocking the most annoying sites. Note that the site is specified as regular expression. Therefore the dot before the TLD must be escaped by a preceeding backslash. [NC] tells the rule to ignore captialization. The last line finally will return an Access Denied error to those sites.


Twitter Bookmark Blocking Content by Referer  at del.icio.us Facebook Google Bookmarks Digg Blocking Content by Referer Bookmark Blocking Content by Referer  at YahooMyWeb

Trackbacks


Trackback specific URI for this entry
    No Trackbacks

Comments


    #1 guruz on 10/10/08 at 03:11 PM [Reply]
    *Why not the other way? Block all requests with a referer != empty referer or != your-site that want to request .jpg,.gif etc?
    :-)
    #1.1 Carsten Schlipf on 10/10/08 at 03:20 PM [Reply]
    *Hi Markus, how ware you doing? The reason is because I don't want to block everything per se. I just want to block the biggest bandwidth consumers.
    #2 guruz on 10/10/08 at 05:53 PM [Reply]
    *Ah ok :-)

    I recently had someone using a picture of my blog for an ebay auction. I replaced it with a banner to my site :-D

    I am good. My diploma thesis is turned in and my flight to Oslo (to my gf and to job search) is going next friday =)

Add Comment

HTML-Tags will be converted to Entities.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA