How to display a replacement image when you are being hotlinked
To prevent hotlinking from other sites to your images, you can use the piece of code below to replace
your images with another image of your own choice.
RewriteEngine On, causes the Apache rewriter to be turned on. The next two lines use the ReWriteCond command
to use regular expressions to search for matches, the [NC] means apply no case sensitivity.
The last line, RewriteRule makes any files that complete with a common graphics format extention to be
replaced with a file called 'yourownimage.gif'. The final [L] cause the rewrite engine to stop any more rules being applied.
HOW TO STOP HOT LINKING 101
Having others hot link to your site can cause a real problem with the leeching of your bandwidth
over a period of time. This can cost you alot of money in hosting charges and is tantamount to theft.
By simply editing the .htaccess file on your Apache Web Server you can redirect
or completely block hot linkers and hot linking from your site.
Use the Free Hot Link Checker below to test whether your website is currently protected from hot linkers. Once you've made modifications to your .htaccess you can recheck and see if it works.
IMPORTANT: mod_rewrite needs to be enabled in order to use the following aspects of .htaccess.
(Also, don't forget to clear your browser cache or use Ctrl-F5 on Internet Explorer to ensure you are seeing the correct data!)
Use the Free Hot Link Checker below to test whether your website is currently protected from hot linkers. Once you've made modifications to your .htaccess you can recheck and see if it works.
IMPORTANT: mod_rewrite needs to be enabled in order to use the following aspects of .htaccess.
(Also, don't forget to clear your browser cache or use Ctrl-F5 on Internet Explorer to ensure you are seeing the correct data!)
|
Enter the full url of an image on your website, to see if it can be hotlinked and displayed externally to your site.
|
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteRule .*\.(gif|jpg|png|bmp)$ /images/yourownimage.gif [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteRule .*\.(gif|jpg|png|bmp)$ /images/yourownimage.gif [L]
Instead of replacing the original image with another image, you can display a '403 Forbidden' error page
by using the following block in the .htaccess. Note the [F] which conditionally block some urls.
RewriteRule .*\.(gif|jpg|png|bmp)$ - [F]
How to block hotlinking from specific domains
The next example .htaccess code prevents hotlinks from specific domains. This can be useful to allow some hotlinking, but prevent access from high traffic sites such as myspace. Note the [OR] directive is used to combine rules i.e this rule and the following rule.(Note the missing ! -pling, for NOT-)
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?otherblog\.com/ [NC]
RewriteRule .*\.(gif|jpg|png|bmp)$ /images/yourownimage.gif [L]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?otherblog\.com/ [NC]
RewriteRule .*\.(gif|jpg|png|bmp)$ /images/yourownimage.gif [L]
As with all firewall or conditional blocking of urls, you should be careful not to unintentionally disallow access to certain parts of your site and images, however prevention of bandwidth theft is an important consideration for any webmasters managing a website and its content.
Use the Hotlink Checker at the top of this page to see if your website allows hotlinking. If it does, try making the modifications suggested above and retest. Good luck and happy hotlink blocking.