• Hello,
    I would like to set a hotlink protection (via htaccess) but need your help.
    There is a long article (http://perishablepress.com/creating-the-ultimate-htaccess-anti-hotlinking-strategy/) where I found 2 nice codes. Here they are:

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER}     !^$
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$           [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\. [NC]
     RewriteRule \.(gif|jpe?g?|png)$                             - [F,NC,L]
    </ifModule>
    
    # hotlink protection via stupid htaccess tricks
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER} !^$
     RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.tld/.*$ [NC]
     RewriteRule .*\.(gif|jpg)$ http://www.domain.tld/eatme.jpe   [R,NC,L]
    </ifModule>

    QUESTIONS:
    Could you pls connect them to get this:
    1) Not [anything].domain.[anything] but [anything].domain.com
    2) This should work for domain mapped also (for sub-sites).
    3) The result of the “theft” should be one definite picture (http://domain.com/image-stop-hotlinking.jpg).

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Sure

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER}     !^$
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$               [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?(domain.com|mappeddomain.com|anotherdomain.com) [NC]
     RewriteRule \.(gif|jpe?g?|png)$                                 - [F,NC,L]
    </ifModule>
    Thread Starter GrayHunter

    (@grayhunter)

    Thank you, but
    2) new domains should not be added manually – it’s impossible, there are lots of them new every day…
    3) I can’t find this in your code…

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You can’t magically automate #2 unless you write a script to update your .htaccess every time you add a new domain. It’s just what it is.

    IMO #3 is a silly idea. It’s just going to cause you more bandwidth so no one bothers with it. But if you insist, the last RewriteRule becomes this:

    RewriteRule .*\.(gif|jpe?g?|png)$ http://www.domain.tld/eatme.jpe   [R,NC,L]
    Thread Starter GrayHunter

    (@grayhunter)

    2) I see… may be there is such plugin anywhere?
    Or is it possible to protect only the main site for example?

    3) Ok, thx!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Maybe. Not one I know of, though.

    If you only want to protect the main site, you’d change the RewriteCond %{HTTP_REFERER} bit to check for JUST the main site.

    Thread Starter GrayHunter

    (@grayhunter)

    Good, but could you give me the full code pls? Let the main site domain be domain.com.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Should be this:

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com  [NC]
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$               [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?(domain.com|mappeddomain.com|anotherdomain.com) [NC]
     RewriteRule \.(gif|jpe?g?|png)$                                 - [F,NC,L]
    </ifModule>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hotlink Protection – Multi Site’ is closed to new replies.