What's wrong with my htacess file (can't disable hotlinking of images)

Discussion in 'Site & Server Administration' started by ubuntu2006, Apr 30, 2009.

  1. #1
    I've read many tutorials on blocking hotlinking of images and trying to get it to work on my site. This is my htaccess file in the root directory:

    RewriteEngine on
    RewriteRule ^[^:]*\.(php|src|jpg|jpeg|png|gif|bmp|css|js|inc|phtml|pl|ico|html|shtml)$ - [L,NC]
    RewriteRule ^index.php?title - [L]
    RewriteRule ^(.*)\&(.*)$ $1\%26$2
    RewriteRule ^(.+)$ /index.php?title=$1 [L,QSA]
    
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mywebsite\.com($|/) [NC]
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?myotherwebsite\.com($|/) [NC]
    RewriteRule \.(gif|jpg|jpeg|png|mp3|mpg|avi|mov)$ - [F,NC]
    Code (markup):
    I also have placed this in my images folder:

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mywebsite\.com($|/) [NC]
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?myotherwebsite\.com($|/) [NC]
    RewriteRule \.(gif|jpg|jpeg|png|mp3|mpg|avi|mov)$ - [F,NC]
    Code (markup):
    Whether I use the httaccess file in my image directory or whether I place the code to block hotlinking in my root directory and image directory my site still allows hotlinking. Could someone offer help on getting this to work? I think I'm really close but just missing something.
     
    ubuntu2006, Apr 30, 2009 IP
  2. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's the point of this line?
    RewriteRule ^[^:]*\.(php|src|jpg|jpeg|png|gif|bmp|css|js|inc|phtml|pl|ico|html|shtml)$ - [L,NC]

    This maybe blocking the next rewrite rule on the images.

    Cheers,
     
    Lpe04, Apr 30, 2009 IP
  3. ubuntu2006

    ubuntu2006 Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I believe it allows short urls for those types of files and I think you are correct. I tried to take out that line completely and all images on article pages (my site is wiki with thousands of pages) showed up blank. So taking it out is not an option. I am stumped.
     
    ubuntu2006, Apr 30, 2009 IP
  4. ubuntu2006

    ubuntu2006 Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Btw ... problem is solved. It turns out the file was working but my browser's cache made it seem like hotlinking was still allowed. When I doubled checked after clearing my browser ... images are not shown when hotlinked.
     
    ubuntu2006, Apr 30, 2009 IP
  5. AviAtriX

    AviAtriX Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ALWAYS! clean yor browser chache after making any sort of server changes .. or just turn off browser chache .. :)
     
    AviAtriX, May 1, 2009 IP