htaccess hotlink protection not working for subdomains

Discussion in 'HTML & Website Design' started by NoobieDoobieDo, Sep 15, 2007.

  1. #1
    I have tooled my htaccess to prevent hotlinking.

    If you try to hotlink to :
    http://mysite.com/img/bla.jpg
    Code (markup):
    it works fine, the linking is blocked and a replacement image is sent.

    BUT, if you hotlink to :
    http://subdomain.mysite.com/img/bla.jpg
    Code (markup):
    Hot linking protection doesn't work.

    Any ideas ?

    Thanks
     
    NoobieDoobieDo, Sep 15, 2007 IP
    gemini181 likes this.
  2. opeth49

    opeth49 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's your code?
     
    opeth49, Sep 15, 2007 IP
  3. NoobieDoobieDo

    NoobieDoobieDo Peon

    Messages:
    1,456
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's REALLY long, it was generated by my cpanel. Here is an example

    
    RewriteCond %{HTTP_REFERER} !^http://mysite.net/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://mysite.net$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://subdomain.mysite.net/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://subdomain.mysite.net$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://myspace.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://myspace.com$      [NC]
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ /sad.jpe [L]
    Code (markup):
    I have a few subdomain. I'm thinking the code generated by cpanel is very inefficient since it's very repetitive. I'm sure there is just one simple change I'm missing.
     
    NoobieDoobieDo, Sep 15, 2007 IP
  4. opeth49

    opeth49 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're right it is quite inefficient. I believe you could replace all those RewriteConds that have mysite in them with this one:

    Change the (dot) for a . as the system prevents me from posting "links".

    If that doesn't work, then there could be a redirection somewhere before this one that would prevent it from working.
     
    opeth49, Sep 15, 2007 IP
  5. NoobieDoobieDo

    NoobieDoobieDo Peon

    Messages:
    1,456
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hrm.. thanks for the code, it seems to cut down on the repetitiveness but hotlinking is still working for my subdomains.

    Very strange !

    Thanks
     
    NoobieDoobieDo, Sep 15, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    I assume that .htaccess in in the web root for only mysite.net ?

    Also assuming you are on a shared host, put the .htaccess in the web root for your subdomains.

    Also, the be on the safe side, take out the slash from the end of that pattern, like so:

    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com [NC]
     
    krt, Sep 15, 2007 IP
  7. NoobieDoobieDo

    NoobieDoobieDo Peon

    Messages:
    1,456
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks a lot krt. It seems that if each web root for the sub domains doesn't have the filtering htaccess in it hot linking will still work.
     
    NoobieDoobieDo, Sep 16, 2007 IP