Lighttpd mod_rewrite Hotlink Protection To Display Image Message

by on June 12, 2008 · 3 comments· LAST UPDATED November 7, 2010

in , ,

Many of our regular readers like to know more about lighttpd hotlink protection using mod_rewrite. Lighttpd can use HTTP referrer to detect hotlink and can be configured to partially protect hosted media from inline linking, usually by not serving the media or by serving a different file.

Lighttpd anti hotlinking configuration - redirect to another media

Open lighttpd.conf configuration file:
# vi /etc/lighttpd/lighttpd.conf
Append the following directive to redirect to a default picture called /hotlink.png:

$HTTP["referer"] =~ ".*BADDOMAIN\.com.*|.*IMAGESUCKERDOMAIN\.com.*|.*blogspot\.com.*" {
  url.rewrite = ("(?i)(/.*\.(jpe?g|png))$" => "/hotlink.png" )
}

So if anyone from *.blogspot.com linked www.cyberciti.biz/image.png it will be replaced with www.cyberciti.biz/hotlink.png. I've written small script to detect excessive hotlink from log file and ban all those domains. Most types of electronic media can be redirected this way, including video files, music files, and animations etc.

Related: Apache web server user can stop leechers using mod_rewrite / .htaccess rules.



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 3 comments… read them below or add one }

1 Leo February 8, 2010 at 7:07 pm

Hello Vivek!

Thank you very much for this entry.

You could copy the script for autoban domains with excessive hotlinking?

Reply

2 Anthony August 11, 2010 at 4:40 pm

Thank you for this great piece of coding, however after hours of playing and testing I still can’t get something to work. Instead of rewriting in this example to hotlink.png, is there a way to rewrite to an html file? Yes I tried simply replacing the hotlink.png with hotlnk.html and it did not work.

Sorry to bump an old post, but this is perfect for what I need.

Thanks,
Anthony

Reply

3 Elliott Back November 6, 2010 at 9:36 pm

I think you mean leechers, lechers are another thing entirely. But good article, and I hope to detect and log hotlinks on my domains shortly…

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 9 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.

Tagged as: , , , , , , , , , , , , , , , , ,

Previous post:

Next post: