How to get links (and more) from your hotlinked…
A few days ago, a friend of mine told me has an image on one of his websites hotlinked in a numbers of forums and blogs, and he asked me if he could get any benefits from it. I’ve thought a little about the situation, and at the end I’ve decided to share my conclusions in a post.
So, this is how you can benefit from having your images hotlinked on other websites. I hope you’ll enjoy the reading.
What’s hotlinking?
First of all, a brief introduction for those few people that don’t know what hotlinking is. In very simple words, an hotlinking occurs when a page on website ABC loads some objects (tipically images) hosted on website XYZ. A very common situation is, for example, website ABC’s page having something like this in its HTML code:
Very simple, and very debated.
Common approach to hotlinking
The problem with hotlinking is that everytime ABC site’s page is loaded, a request for the image is made to server XYZ: this means that XYZ has its own bandwith consumed without being actually visited. And the more ABC gets visits, the more XYZ server is stressed.
This leads the majority of the webmasters to prevent hotlinking by denying external requests to their images. You’ll find a plenty of articles on how to do this and I’ll not go into details here.
My aim is to show a different way of dealing with the “problem”, so let’s go on.
Let people hotlink your images, and store data
Allowing people hotlinking can turn into getting nice information, and concrete benefits too, if we know how to take advantage of it.
Our first step is thinking to the technical aspects of the situation. We have a page that’s requesting an image to our server. In the time span from the request to the answer, many things might happen. Because how our server handle the request is our own choice: we might just let the image being served, denied, or we might do something different…
In the following picture, there’s just a screenshot of some of the requests my last post makes to my own server and external ones:
You can see an image is requested to Twitter, for example, and the server replies with a 200 OK status code, giving me my thumbnail image.
I’ve set my own server, instead, to reply with a 304 status code that tells the browser the file hasn’t been modified since the last visit (so the browser reloads it from the cache).
If an image was requested from an external server, I might set the server replying with a 302 status code and redirecting the request to another file to do stuff (like storing somewhere information related to the request), before serving the image.
A little statement is needed here: handling the request in a nasty way is possible (ie. read something about Cross-Site Request Forgery).
I’m not suggesting doing any malicious actions in any way.
Intercepting the request
From this point, I’ll include some actual code in the post. My environment is Apache + PHP, but different web servers and programming languages can be used as well. So, just get the idea…
First of all, I’ll set a rule in my .htaccess file.
RewriteCond %{HTTP_REFERER} !yourwebsite.com
RewriteRule (.*).(jpe?g|gif|png|bmp) http://www.yourwebsite.com/script.php?requestedImage=$1.$2 [R=302,L]
These two lines will check if the request is arriving from my own website, and if not the requested file is redirected to a PHP script. The query-string will store the requested URL.
The screenshot shows a line in the table in which a page named request.html of my website zen2seo.it is requesting an image hosted on http://en.posizionamentozen.com, with relative path wp-content/uploads/2012/07/anchor-text1-204×72.jpg
Storing data
Once I’ve sent the request to the script, I may perform different actions before giving the image to the client. For example, in this script I save a few information into a database table (please notice I’m not a programmer, so maybe this is not the best possible code. But it works…):
$host="MYHOST";
$user="MYUSER";
$password="MYPSW";
$myconn=mysql_connect($host,$user,$password) or die("Connection error");
$db_name="MYDB";
mysql_select_db($db_name,$myconn);
$requestdate = date('Y-m-d');
$requestedImg=$_GET['requestURL'];
$referer=$_SERVER['HTTP_REFERER'];
/* SCRIVO NELLA TABELLA */
$query_sql="INSERT INTO Hotlink VALUES('".$referer."','".$requestdate."','"$requestedImg"')";
$result=mysql_query($query_sql,$myconn);
...
These lines, simply, connect to a database and write in the table named Hotlink three values: the web page that was requesting the file, the date of the request, the hotlinked image URL.
Serving the image
Once I’ve stored the data, I send back the image to the client (the code just shows how to handle a jpeg file; you’ll need to check the extension of the requested file and use the proper PHP function to handle png, gif or bmp).
$imgJpg = imageCreateFromjpeg('MYWEBSITE'.$requestedImg);
imageAlphaBlending($imgJpg, true);
imageSaveAlpha($imgJpg, true);
header("Content-type: image/jpeg");
imagejpeg($imgJpg);*/
Notice that the server is declaring that the Content-type of the response is an image (and is serving it back).
Using the information
At this point of the post, you should already have had some ideas about how to use the information you’ve collected, but I’ll give you some possibilities…
1) Finding who has embedded your infographic and removed the link
Usually, when you publish an infographic, you also let people get the HTML code to embed it in their websites. If someone has decided to hotlink your image and remove the link, you can ask them for the due crediting (The same for any image you own rights for; ie. logos, etc).
2) Using your images as advertising
If you notice that a particular image is very requested, you might specify a specific redirection rule for it and return a little different version of it to external websites. It might be the original one now containing your logo or a call to action, or a GIF image with two frames (the actual image + an advertising). Let your creativity be free…
3) Finding pages to be featured on
If you notice that a particular page requests your image a lot of times per day (that means it gets many visits), you might be interested in being featured on that page or website. Maybe you can get in touch with the webmaster and ask for an advertorial, a guest post, a banner…
4) Doing retargeting for your “visits”
This point is a little controversial, but I’ll add it the same… When someone loads your images on an external site, you might set a cookie (via the PHP script) for that “visit” and do retargeting on that visitor (I know setting a cookie might sound a bit grey-hat, anyway).
Conclusions
The ones I’ve listed are just a few possibilities you have by collecting data related to your hotlinked images, bu also others exist. Adding a bit of code you might handle requests coming from Google Images SERPs, for example (HTTP referer is not passed here, unless someone clics on the image)…
What to do and how, in conclusion, depends on your specific needs and your specific environment, mainly if you can’t access logs file (that – however – aren’t so nice to be read). Anyway, I hope I’ve given you some ideas.
If you will try, then let me know if it will bring you some good results. In the meanwhile, if you liked this post, links and shares are always well appreciated!
12 COMMENTS
Intelligent article, written with undoubtful expertive on Seo subjects.
All my complliments.
Francesco
Thanks Francesco, much appreciated π
You are the best Giuseppe! Very happy to have given you the inspiration to write the post and to discover you never stop to test and being a better programmer π That’s the right way!
Hi Simone, glad you liked it! I’m sure you’ll be able to go deeper with the script and get even more π
Nice article, but let me ask you one question: what does this have to do about SEO (remember SEO=search engine optimization) ? The answer is: nothing. Hotlinking can have some advantages for the reasons you mentioned, but from you are saying it has no benefits towards search engine optimization whatsoever. The title of your article is misleading.
Hi Costello,
thanks for stopping by and leaving a comment. I disagree, anyway, with you stating this has nothing to do about SEO. I was citing getting credts links o mining guest posting opportunities: isn’t it offpage SEO, maybe?
Nice article but i think u are more of techie/ admin π than seo
Well, being I can’t code almost at all, I take it like a compliment, eheheh!
Intresting π
I bought domain with history, it was image storage.
And now i have many hotlionk requests… maybe it time to use it π
I know this is an old post but it still comes up in the SERP’s these days.
What about this scenario?
Site A is hotlinking an image of site B.
Site B deletes the image so site A now just shows an X instead of the image (actually now there is a dead link).
Site B sets a redirect in the htacces file where the image/image.jpg link is replaced by a url to a page with real content.
Should this improve the SERP of that particlular content page in any way?
n theory you would now have a free backlink from site A to site B.
Hi DPH,
in reality the link is placed in the img tag and not in an anchor tag, so I don’t think this is a link that counts for rankings.
Yes you got a good point there.
I think it is better to replace that .htacces redirect and give the hotlinker a stupid image back which might force him to stop hotlinking from my site.
thanks for the reply