Prevent your blog from getting image hot linkings
One of the most annoying part of blogging is the images on your blog are getting hot linked by others. The most common ones that we’ve seen are those spammy blogs from blogspots, livejournals etc, which they simply copy over the images uploaded on your blog posts.
Meaning that doing so, they won’t have to host those images, and they’re stealing bandwidths from you. But you have a choice to control from being hot linked by others just to save some of your bandwidths. Or you’re simply pissed off as those original images that you’ve created by your own have simply been copied and pasted over. And they’ve even stolen the originality of your content.
To prevent from hot linking, you’ll just need to add some codes to your .htaccess, such as the following codes which I wanna prevent the four domains to hot link to my images.
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?myspace\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blogspot\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?wordpress\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?livejournal\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpg|gif|bmp|png|jpeg)$ /images/sorrynothotlinking.php [L]
The users will get redirected to my PHP page /images/sorrynothotlinking.php which I build using PHP function imagecreatefromjpeg() to output an image that shows the “No Hot Linking” messages. You’ll probably could make it to point to another image file with either a .gif or .jpg extension. But I’ve found somehow the redirection will keep looping as it seems to have confused the webserver. So, I’ve then made a PHP script to do so.
By the way, in the occasion you wanna block all others from hot linking to your images except with few domains that you wanna allow, (lets say mysite1.com and mysite2.com as follows), you can add the following codes to your .htaccess
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite1\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite2\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpg|gif|bmp|png|jpeg)$ /images/sorrynothotlinking.php [L]
Please note that if you only allow a few domains to be able to hot link to your images and block all the rest, will prevent those images to show up on email clients as well. As you’ll have lots of readers to subscribe your blog feed via FeedBlitz which delivers blog feed via emails. When they open up the feeds on the email clients they’ll see the “No Hot Link” images on each post and this is ugly.
The best way is to use method 1, just to block those sites or blogs or those you dislike which you’ve discovered that they hot link to you.
Tags: blogger, blogging, Blogging tips, Hot Linking