Difference between revisions of "Advertising in Hotlinked Images"
AzraelBrown (talk | contribs) |
AzraelBrown (talk | contribs) |
||
Line 33: | Line 33: | ||
RewriteRule (.*\.jpg)$ /hotlink.php?url=http://www.thingsville.us$1&temp=1 [R] | RewriteRule (.*\.jpg)$ /hotlink.php?url=http://www.thingsville.us$1&temp=1 [R] | ||
</pre> | </pre> | ||
− | The first line allows the referrer to be [http://www.thingsville.us Thingsville], because we don't want replacement on my own websites. | + | The first line allows the referrer to be [http://www.thingsville.us Thingsville], because we don't want replacement on my own websites. TIn the second line "^$" represents "a blank field", which allows any user who does not have a referrer. While this ''could'' allow some hotlinkers to slip by, it would negatively affect more users than help. The third line allows Google Image Search, just because I'd like people to find my images as they are on my website. The last is the replacement. It says that, aside from the exceptions above, any JPEG image request should be forwarded to my file 'hotlink.php' (my PHP file which does the image-building), and passes on the URL to the image requested so that my script can properly replace it. |
The script I wrote first checks if it has a 'cached' version of the hotlink-replacement image; if not, it finds the original image requested, resizes it, and adds my little banner to the top and bottom of each image. | The script I wrote first checks if it has a 'cached' version of the hotlink-replacement image; if not, it finds the original image requested, resizes it, and adds my little banner to the top and bottom of each image. |
Latest revision as of 21:47, 13 December 2008
As someone who owns my own servers and spends a bit on bandwidth, running dozens of domains and websites, the practice of hotlinking images is a pain in the butt. I have come up with this fun plan to make hotlinking work for me, plus not piss anybody off.
Contents
What is Hotlinking?
Hotlinking is the process of using my image's URL and putting it on somebody else's website. The file itself remains on my server, but the image appears in the other person's website. What this means is their 1K of HTML gets served by their webserver, but my 30K image is served from my webserver -- the bulk of the data transfer is on me, using up the bandwidth I pay for.
Another reason to dislike hotlinking is that when somebody takes images from my website, and posts them on their website, it looks like they are the source of the cool images. I have to disagree: there is so much hotlinking being done to my websites, it is obviously clear that I am the cool one in this situation. This doesn't stop them from downloading the image and uploading it to their server without citing their source, but when the images are still on my server and in my control, I can do something about it.
The Traditional Way To Deal With Hotlinkers
The traditional method of rectifying a hotlinker is to use Apache's mod_rewrite module to replace their intended image with an entirely different one. For example, on Kitschy-Kitschy-Coo.com, we perform this switcheroo behind the scenes:
While I cannot go into how mod_rewrite works in great detail (Google can help you with that), the system basically allows your webserver to alter what a particular URL returns, depending on the site visitor. With mod_rewrite, you can tell your Apache webserver that if a request comes from a referrer that isn't your own website, to 'rewrite' the URL and send a different image instead.
The drawback of this method is that bandwidth is still being used to serve the replacement image. The replacement image is a deterrent, because hopefully the culprit will see that their hotlinking didn't work, and delete the link. This doesn't always happen, especially in message boards where the admins don't care much.
The Advertising Route
There's so much hotlinking going on with our websites, that it really makes me look like a jerk to continually chastize people for stealing our images. The KKC image above is actually quite tame: I have other images for other sites that use much, much more vulgar language. While it's fun to see somebody's MySpace page wallpaper declare the owner an asshole for hotlinking, it doesn't help traffic to my websites, and that's really part of my problem with hotlinking. So, how do I turn hotlinking into something that brings people to my website?
The answer: Use mod_rewrite and PHP's GD library to add an advertisement to every image served with a non-local referrer. This causes:
I won't go into great detail about how to write the PHP code: you can decide how you want to alter your images to reflect your own website's personality. This could be as simple as a watermark, to completely changing the image. However, once you write a program to change the images, you want to make sure it is not replacing them on your own webpages. The key to this is the httpd.conf file. For example, the rewrite rules for Thingsville, US are:
RewriteCond %{http_referer} !^http://www.thingsville.us [NC] RewriteCond %{http_referer} !^$ [NC] RewriteCond %{http_referer} !^http://images.google.com [NC] RewriteRule (.*\.jpg)$ /hotlink.php?url=http://www.thingsville.us$1&temp=1 [R]
The first line allows the referrer to be Thingsville, because we don't want replacement on my own websites. TIn the second line "^$" represents "a blank field", which allows any user who does not have a referrer. While this could allow some hotlinkers to slip by, it would negatively affect more users than help. The third line allows Google Image Search, just because I'd like people to find my images as they are on my website. The last is the replacement. It says that, aside from the exceptions above, any JPEG image request should be forwarded to my file 'hotlink.php' (my PHP file which does the image-building), and passes on the URL to the image requested so that my script can properly replace it.
The script I wrote first checks if it has a 'cached' version of the hotlink-replacement image; if not, it finds the original image requested, resizes it, and adds my little banner to the top and bottom of each image.
Result
The result is heavier bandwidth usage to my websites, but it does put my URL in far more visitor's faces than ever before. Of course, there is no actual link to click on, but that is a minor issue. In the majority of advertising, gaining recognition is the important part. Even if someone sees my image, clicks on a link, then goes away, it is no guarantee that they will return. If they start seeing my re-branded images all over the internet, they will begin to associate my website with cool pictures and make a point of visiting the site to find more. Many websites pay a lot of money to get their name on other websites through banner ads or AdWords, but the end result of my plan is a lot of free advertising, thanks to people who hotlink to my images. The cost of my bandwidth is worth it compared to the number of eyeballs the advertising can potentially bring.