Stop the hot-linkers

The purpose of this tutorial is to show you how to stop people using images hosted on your domain within their own websites.

You can use the information in this tutorial to force hot linked images to be redirected to another image to dub the person a lecher. This, however, does not save you bandwidth since an image is still being pulled from your server.

All of the code below goes into .htaccess on your server (this is a system file and is set to be hidden, if you can’t view it then check your FTP client settings). If you are experiencing problems with these scripts, then please insure that mod_rewrite is enabled.

Operators Dictionary:
! - Not
^ - Match the beginning of the search
$ - Match the end of the search

Bracket Dictionary:
[L] - Last (this is the last before to apply the rule)
[NC] - Not Case-sensitive (does not differentiate between upper and lower case)
[R] - Redirect (forces redirection)

The following code allows only sites from mydomain.com to use the images in the directory:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(bmp|gif|jpe?g|png)$ -[F,NC,L]

Line 1 declares the ability to rewrite.
Line 2 sets it so that that if the referral is empty the rule does not apply.
Line 3 sets is so that if the referral is the domain then the rule does not apply.
Line 4 declares that any file with the extention bmp, BMP, gif, GIF, jpg, JPG, jpeg, JPEG, png, and PNG will go to an empty site.

The following code allows domains example.com and example2.com to use the image while preventing others from hotlinking:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2.com/ [NC]
RewriteRule \.(bmp|gif|jpe?g|png)$ -[F,NC,L]

Line 1 declares the ability to rewrite.
Line 2 and 3 checks if the referral is not of the domains example.com and example2.com. If it is, then the condition is not met.
Line 4 declares that any file with the extension bmp, gif, jpg, jpeg, png, and their capitalized recipricals will go to an empty site.

The following code redirects any image hotlinked from your site to another image:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(bmp|gif|GIF|jpe?g|png)$ http://www.mydomain.com/rawr.gif [R,L]

Line 1 declares the ability to rewrite.
Line 2 checks if there is not a referral.
Line 3 checks if the referral is itself.
Line 4 declares that all extensions of bmp, gif, GIF, jpg, jpeg, and png will redirect to the image rawr.gif in the root directory.

Digg this article

17 Responses to “Stop the hot-linkers”

  1. Ryan Says:

    Amazingly enough, I think I actually understood that :) . Great tut and I’m sure I’ll be putting it to use.

  2. rick` Says:

    good stuff :) i knew most of it already though ;)

  3. » Blog Archive » IP ban or redirection Says:

    […] « Stop the hot-linkers […]

  4. testing Says:

    Hello!Just a testing :)

  5. car classic sales Says:

    car classic sales…

    Fresh information about car classic sales….

  6. household credit card services Says:

    household credit card services…

    ka-ka-sh-ka 2559828 Technologies of household credit card services…

  7. black cat girl Says:

    black cat girl…

    Value information about black cat girl…

  8. craig huey Says:

    craig huey…

    craig huey co…

  9. doggie skins Says:

    doggie skins…

    Good information about doggie skins….

  10. spreadeagle bdsm dru berrymore Says:

    spreadeagle bdsm dru berrymore…

    ka-ka-sh-ka 2559828 Actual news on spreadeagle bdsm dru berrymore category….

  11. sexy smoking gallery Says:

    sexy smoking gallery…

    ka-ka-sh-ka 2559828 sexy smoking gallery foundation…

  12. arctic monkey Says:

    arctic monkey…

    arctic monkey intro…

  13. starfire hentai teen titans pictures Says:

    starfire hentai teen titans pictures…

    ka-ka-sh-ka 2559828 starfire hentai teen titans pictures info and more…

  14. the mack within Says:

    the mack within…

    the mack within intro…

  15. most wanted webshots wmw Says:

    most wanted webshots wmw…

    Good information source for most wanted webshots wmw….

  16. health insurance individual unicare Says:

    unicare insurance life health individual insurance unicare health

  17. ocljlwijlmcds Says:

    ocljlwijlmcds

Leave a Reply