htaccess

Discussion in 'Apache' started by Psychotomus1, Mar 9, 2007.

  1. #1
    How can I stop people from hotlinking to files on my server. they made me run out of bandwidth by doing that =(
     
    Psychotomus1, Mar 9, 2007 IP
  2. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Looking on google I found out this:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

    Where mysite.com is your site. It should block requeststo jpe?g|gif|bmp|png files from other sites, and replace it with /images/nohotlink.jpe.
    Hope this helps!
     
    cbn81, Mar 9, 2007 IP
  3. Psychotomus1

    Psychotomus1 Banned

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what about other files. such as avi's. zip's,rar's.mp3's and midi's?
     
    Psychotomus1, Mar 9, 2007 IP
  4. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Wel you can add in this line
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
    The extensions you want to block.
    Try it out and let us know if it works!
     
    cbn81, Mar 9, 2007 IP
  5. Psychotomus1

    Psychotomus1 Banned

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    works =) it works ;]
     
    Psychotomus1, Mar 11, 2007 IP
  6. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Perfect! I'm happy I helped you out!
    Bye
     
    cbn81, Mar 11, 2007 IP
  7. Psychotomus1

    Psychotomus1 Banned

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    this migght be more difficult. how could I redirect them to my homepage instead of getting a 404 when they try to access the file if someone is hotlinking to them.
     
    Psychotomus1, Mar 11, 2007 IP
  8. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
    You can replace /images/nohotlink.jpe with the url of the home (i.e. index.htm), but you could get something bad, for example if someone is hotlinking an image in a webpage. Anyway for mpe and zip files it should work.
     
    cbn81, Mar 11, 2007 IP
  9. Psychotomus1

    Psychotomus1 Banned

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Could I a dd 2 rewrite conditions?
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]
    and
    RewriteRule .*\.(zip|avi|rar|midi|mp3)$ /index.php [L]
     
    Psychotomus1, Mar 11, 2007 IP
  10. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I think so. try it!
     
    cbn81, Mar 11, 2007 IP