Jump to content
xisto Community
Sign in to follow this  
Avalon

How To Stop Image Hot Linking for a selected directory.

Recommended Posts

Those of you that don't know what is meant by 'hotlinking', it is when someone directly links to an image on your site so it will display on their site. This is what is called 'bandwidth theft' and being as accounts here have a limit on bandwidth, your bandwidth limit could be exceeded by someone else hotlinking to your images.

 

As most users of cPanel will know, there is an option to disable hotlinking of images in the "Site Management Tools" section.

404.png

However, this disables hotlinking to all directories, what if you only want to disable hotlinking on some directories? Perhaps you want to people to link to some images, say an advertising banner for your site or something similar?

 

Here's how to do it. Open a text editor like Notepad, copy the code below and paste it into the editor.

 

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?mudmall.com/.*$ [NC]RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$  mudmall.com/img/nolink.gif [R,NC]
Change the domain name where is says, 'mudmall.com' to your domain name and change the 'RewriteRule' line so it has the file extensions you want to deny access to. What I have there will cover most image formats, but you may want to add extensions like 'avi', 'mp3', 'wmv' if you have those types of files. Then change the RewriteRule URL so it points to an image you want displayed when someone tries to hotlink to your file, or you can remove the URL if you don't want to display an image. If you do use an image, make sure it is in an unprotected directory and keep the file size small, mine is only 1.3Kb. Otherwise you will be defeating the purpose of disabling the hotlink.

 

Finally, save the file with the name '.htaccess', (note the period * in front of the name). Now upload this file to the directory/s you want to protect.

 

This is the end result. Here is an image hosted at Imageshack.

404.png

 

Here is the result of trying to hotlink to that same image at my site.

2dragonredfly.gif

 

I hope you find this useful. :)

Share this post


Link to post
Share on other sites

hmmm interesting, tutorial me i would have done it the more agressive way spam email boxes report his ip number something like that.but luckly for me i don't have to many images to be hotlinked.good job avalon.

Share this post


Link to post
Share on other sites

Those of you that don't know what is meant by 'hotlinking', it is when someone directly links to an image on your site so it will display on their site.

It's not really only a direct link to an image, but to a file. But, this tutorial is only for images, obviously.

Share this post


Link to post
Share on other sites

It's not really only a direct link to an image, but to a file. But, this tutorial is only for images, obviously.

183824[/snapback]

Thanks for the clarification truefusion, you are of course absolutley correct. The same .htaccess file idea can be used for any file type. But putting an alternate image for the file is pointless if the original file is not an image, as it will not display.

Share this post


Link to post
Share on other sites

Here's how to do it.� Open a text editor like Notepad, copy the code below and paste it into the editor.

 

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?mudmall.com/.*$ [NC]RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ mudmall.com/img/nolink.gif [R,NC]
Change the domain name where is says, 'mudmall.com' to your domain name and change the 'RewriteRule' line so it has the file extensions you want to deny access to. What I have there will cover most image formats, but you may want to add extensions like 'avi', 'mp3', 'wmv' if you have those types of files. Then change the RewriteRule URL so it points to an image you want displayed when someone tries to hotlink to your file, or you can remove the URL if you don't want to display an image. If you do use an image, make sure it is in an unprotected directory and keep the file size small, mine is only 1.3Kb. Otherwise you will be defeating the purpose of disabling the hotlink.

 

Finally, save the file with the name '.htaccess', (note the period * in front of the name). Now upload this file to the directory/s you want to protect.

 

183755

 

Got it, thanks!

 

My husband was awake so I was able to print it off for future reference. I don't know about adding copies of this file to every folder, as I have so many. For now I am going to stick to using my cPanel hot link protection.

Edited by OpaQue (see edit history)

Share this post


Link to post
Share on other sites

Nothing fancy but hot linking images, stealing bandwith etc its all good.

Having one's bandwith slashed down isn't a good thing. :lol:

Anyway, if I recall correctly, CPANEL's method is the way easier than the alternative method. This guide should help people from having their bandwith totally messed with, though I'd imagine. Good job.

Share this post


Link to post
Share on other sites

Yes, cPanel's method is much simpler, but like I pointed out in my first post...

However, this disables hotlinking to all directories, what if you only want to disable hotlinking on some directories? Perhaps you want to people to link to some images, say an advertising banner for your site or something similar?

This is the whole point of the alternative method.

Share this post


Link to post
Share on other sites

Nice thing.. I have seen such things on diffrent sites.. This could stop thous who always take ideas of signatures in theyr websites or diffrent sigs..I'll definatly use this on my new site.. becaus eit's very useful thing :lol:

Share this post


Link to post
Share on other sites

Here is one problem with this method. You are using the HTTP referal information. Some software (like Ad Muncher) for example, let you change your REFERAL information. If I change the referal information to always be "google.com" for example, then all the images on your site would be broken! :lol:

Share this post


Link to post
Share on other sites

Canada, this script can be used with pretty much any webserver. Simply save it as .htaccess, and use a ftp (or scp) program to upload it to your website like you'd upload a normal image or html file. It will be effective for the directory you upload it to, and to all of its subdirectories.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.