Stop Hotlinking of Images
It used to be easy to do this via the .HTACCESS file with Apache web server hosting. The way it worked was to check the REFERER server variable which shows where the request for a file is coming from. So if it was not a page on your site or a trusted domain, then you could serve up a default image.
The code could be something like this:
Options +FollowSymlinks
# no hot-linking
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*png$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^(www\.)?yoursite\.com/ [NC]
RewriteRule (.*) img/default.gif
Some sites need the line: Options +FollowSymlinks
Others don’t.
What I found recently is that the HTTP_REFERER is not present when I browse with Firefox or IE6 so the above approach doesn’t work.
So it seems like there is no way to stop the hotlinking. But here is an alternative I settled on which works well:
Regularly change the name of your image directory. This is quick and easy to do with an FTP program and you don’t need to move any files. But, of course, you need to update the links to images in your web pages. So to make this quick and easy, you can use PHP to insert the new directory name in your links with echo _IMAGE_DIR;
Sorry I can’t enter php tags here without my blog thinking I’m entering code
Store the value of _IMAGE_DIR in an external file such as common.php containing:
define("_IMAGE_DIR", "images123/");
And include this file at the beginning of each web page with:
include(”common.php”);
Now it’s easy to change the path to your images regularly to stop hotlinkers wasting your bandwidth.
To display a default image in place of those that no longer exist, you can add this code to your .htaccess file:
Options +FollowSymlinks
RewriteEngine On
ErrorDocument 404 http://yoursite.com/image.gif
Here’s some links to people’s pages that know more than me about .htaccess:
http://www.vnwr.com/resources/tutorials/htaccess.html