Direct linking

Direct linking (hot linking) is bad. Its very bad when you own a domain or are hosted for free by someone who owns a domain. You pay for the bandwidth and direct linkers steal it. Its illegal to do so but still you will find many people doing it. You can not stop eac one of them by emailing their hosts. There is a better way of saving your bandiwdth : disabling direct linking from your site. Its easy to do so and you can also teach these theives a lesson by replacing the image they direct link with any image you want to.

Disable it

Open notepad and copy and paste the following code in it


RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com.*$ [NC] RewriteRule \.(gif|jpg)$ - [F]



Change the 'yoursite.com' with your domain name and save this file as .htaccess. If you already have a .htaccsess file, you can just add the above code anywhere in it. Upload the .htaccess file to your root directory. The above code will diable direct linking of .jpg and .gif images from your site as long as your host supports mod rewrite, which most of the hosts do support.

Replace the image

If you want to show a particular image when someone direct links from your site, instead of the above code add the following code in the .htaccess file.


RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com.*$ [NC] RewriteRule \.(gif|jpg)$ http://www.yoursite.com/hotlink.gif [R,L]



Like before, change the 'yousite.com' with your domain name and upload the .htaccess file to your root directory. Here hotlink.gif is the image that will show up when someone direct links from your site. You can use any picture you want like a picture of poo :P or a picture with the messae 'No direct linking ' or even 'Visit My Site (with the url)' for advertising your site or an evil message if you want to. This is a good way to tach lesson to bandwidth theives. You can use the following images if you want to :





Note: Questions regarding this tutorial should be asked here.


« Back