Stop Hotlinking with Lighttpd

by on April 10, 2008 · 2 comments· Last updated April 10, 2008

The technology behind the World Wide Web, the Hypertext Transfer Protocol (HTTP), does not make any distinction of types of links -- all links are functionally equal. Resources may be located on any server at any location. Linking to an image stored on another site increases the bandwidth use of that site even though the site is not being viewed as intended. The complaint may be the loss of ad revenue or changing the perceived meaning through an unapproved context.

Here is easy and simple way to stop hotlinking :
Open lighttpd.conf file:
$ vi lighttpd.conf

#### stop image hijacking (anti-hotlinking)
$HTTP["referer"] =~ ".*BADDOMIN\.com.*" {
        url.access-deny = ( "" )
#      url.access-deny = ( "jpg", "png", "js", "jpeg", "gif" )
}

You can also enforce password protection:

$HTTP["referer"] =~ ".*BADDOMIN\.com.*" {
 auth.require = ( "/" =>
                   (        "method"  => "digest",
                            "realm"   => "Authorized users only",
                            "require" => "valid-user"
                   )
                 )
}

Restart lighttpd:
# service lighttpd restart



You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 2 comments… read them below or add one }

1 drivesoslow April 10, 2008 at 3:54 pm

Wouldn’t be wiser to block all referrers by default and instead use a white list of those allowed?

$HTTP["referer"] =~ “*” {
url.access-deny = ( “” )
}
$HTTP["referer"] =~ “.*GOODDOMIN\.com.*” {
url.access-allow = ( “” )
}

Reply

2 photos china June 13, 2008 at 3:02 am

I dont’t understand this line :
url.access-deny = ( “” )

and why the line
# url.access-deny = ( “jpg”, “png”, “js”, “jpeg”, “gif” )

is commented ? does it meen that every file called out of the domain are bloqued ?

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 9 + 11 ?
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: