.htaccess code for hotlink

Discussion in 'Apache' started by ElvisFan, Jan 7, 2006.

  1. #1
    okay... I have created a .htaccess code and added an image to load should yet another thief steal my images... I have about 10 images stolen every other day... and I spend most of my time renaming my images... so decided that maybe adding a .htaccess code would save me a lot of trouble

    Now the trouble is... I can't seems to make it work.... I have read just about everything there is on the subject... but they omit to tell you how to load and where to load.. both the .htaccess code and the refer image.

    Please can someone shed some light on this issue...

    If I drop my .htaccess code in my images directory... where do I drop my image url... as the image does show in the browser

    http://www.elvis-presley-biography.com/DO-NOT-STEAL.jpg

    but alas it doesn't work to stop hotlinking to images on my site.

    Help, please .... thanks
     
    ElvisFan, Jan 7, 2006 IP
  2. Smyrl

    Smyrl Tomato Republic Staff

    Messages:
    13,740
    Likes Received:
    1,702
    Best Answers:
    78
    Trophy Points:
    510
    #2
    My .htaccess files are in my root directory. Try yours there and let us know what happens.

    Shannon
     
    Smyrl, Jan 7, 2006 IP
  3. ElvisFan

    ElvisFan Peon

    Messages:
    213
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have tried that... as I only want to stop hotlinking to my images... I was told that you need to separate the .htaccess code from the directory where the images is located...

    Please more information... I have two directories, one where my .html files are and the other called images... where all my images go....

    Where do I upload each of the codes... thanks
     
    ElvisFan, Jan 7, 2006 IP
  4. Smyrl

    Smyrl Tomato Republic Staff

    Messages:
    13,740
    Likes Received:
    1,702
    Best Answers:
    78
    Trophy Points:
    510
    #4
    I have a .htaccess question online myself at the moment so am novice with .htaccess. My disable hotlinking code is in my .htaccess file in my root directory. It does not show a forbidden or some such image. If some one hotlinks they get the gray box with red x in corner. You must have a more advanced code than I. I would try .htacceess in root directory, and image in image directory.

    The code I am using is:

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

    Good luck.

    Shannon
     
    Smyrl, Jan 7, 2006 IP
  5. ElvisFan

    ElvisFan Peon

    Messages:
    213
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ... if I do that do I have to change my refer image code to

    http://www.elvis-presley-biography.com/images/DO-NOT-STEAL.jpg

    because that where I will transfer it to... at the moment I have the .htaccess code in the images directory and the refer image in my .html directory...

    when I had it the other way around it still didn't work... need an expert to talk me through how best to solve this problem...
     
    ElvisFan, Jan 7, 2006 IP
  6. Smyrl

    Smyrl Tomato Republic Staff

    Messages:
    13,740
    Likes Received:
    1,702
    Best Answers:
    78
    Trophy Points:
    510
    #6
    Hopefully a mod rewrite expert will be along shortly.

    Shannon
     
    Smyrl, Jan 7, 2006 IP
  7. error10

    error10 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Someone called for a mod_rewrite expert?

    Simple hotlink protection .htaccess rules.

    # Kill hotlinks -- /hotlink.png is the image to be served to the hotlinkers.
    # You can find an excellent example image at t bg rl.com :)
    RewriteCond %{REQUEST_URI} !^/hotlink.png$
    RewriteCond %{HTTP_REFERER} !^$
    # where example.com is your domain
    RewriteCond %{HTTP_REFERER} !^http://example.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://.*.example.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://feeds.feedburner.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://otheralloweddomain.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://.*.otheralloweddomain.com.*$ [NC]
    # add as many domains above as you want to allow
    # Google Cache/Images/etc.
    RewriteCond %{HTTP_REFERER} !^http://images.google.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://216.239.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://64.233.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://66.102.*$ [NC]
    # and now kill the b stards -- use your own URL
    RewriteRule .*[Jj][Pp][Gg]$|.*[Gg][Ii][Ff]$|.*[Pp][Nn][Gg]$ http://www.example.com/hotlink.png [L,R=302]

    Make sure the image URL at the top and the bottom match up!
     
    error10, Jan 7, 2006 IP
  8. ElvisFan

    ElvisFan Peon

    Messages:
    213
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Have no idea what you are trying to say... my problem is where oh where to a drop the .htaccess code and where of where do I drop the image code I want to replace it with... in my directories?

    Tried your example... and I get an error message.. no image no nothing

    please make this simple... for the novice... thanks
     
    ElvisFan, Jan 8, 2006 IP
  9. error10

    error10 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You put it in your top level web directory...but you change example.com to your own domain first! You can also change hotlink.png to your other image name too, but you have to change it at the top and the bottom. :)
     
    error10, Jan 8, 2006 IP