Forum Moderators: phranque

Message Too Old, No Replies

Can I do this with hotlink protection?

         

icephoenix

8:07 am on Feb 27, 2004 (gmt 0)

10+ Year Member



I would try Google for this but I have no idea what words to search...

I have a fansite that gets quite a number of hits and it has a few thousand photos. People post our photos all over fan forums and although we don't mind text-linking to our photos, we hate it when someone posts 10 images from our gallery on a high-traffic fan forum... every time someone opens the thread to read the posts inside, the 10 pictures get redownloaded even if the viewer has no need of seeing them again.

Is there any way of changing my .htaccess file to disallow "remote downloading" of our pictures while allowing downloads from remote text-links to pictures?

Or is it just not possible? :(

Rincewind

2:26 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



You can block hotlinking to your images by adding this code to your .htaccess file.

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

Remember to change example.com to your own domain name.
However, this will block all external links to your images. Basically the server can't tell wither the request form the other web site is a linked or embeded image. I can only suggest putting some text on your pages telling people that hotlinking has been blocked and that they should link directly the the web page not the image.

icephoenix

10:16 am on Feb 28, 2004 (gmt 0)

10+ Year Member



Basically the server can't tell wither the request form the other web site is a linked or embeded image.

I'm out of luck then. But thanks. :)

AprilS

6:40 am on Feb 29, 2004 (gmt 0)

10+ Year Member



icephoenix - I had to read the past few remarks a few times to see why the solution "Rincewind" provided wouldn't work for you.

Using "mod rewrite" will prevent people from stealing your bandwith because it is looking at which server is requesting the image. If it is your server/domain it will display the image - if the request is coming from a different domain (that you haven't specified) it will provide them with a broken image....OR you can make it so it displays some sort of warning image you choose.

Now, if sites but a text link to your image - this will work because it is sending the user to your site to view the image.

I hope I understood your concerns and responded appropriately.

icephoenix

5:43 pm on Feb 29, 2004 (gmt 0)

10+ Year Member



Thanks for the reply, April. So are you suggesting that I just go about this in the normal way, with htaccess, using the code someone else posted in this thread?

I actually used to have my domain's htaccess set to disallow remote linking (I believe I had the same htaccess as the one posted in this thread) but text links to images hosted on my domain wouldn't load. People would have to copy the image's location and paste it into their browser address bar to get the image to load properly. :\

Or is this "mod rewrite" you're talking about something different? I'm not that familiar with htaccess files, you see.

icephoenix

5:49 pm on Feb 29, 2004 (gmt 0)

10+ Year Member



Here's another htaccess question...

How do I use htaccess to indicate which sites to disallow remote linking to? I want all other sites allowed hotlinking, except for a few certain sites.