Prevent HotLinking!

Discussion in 'Site & Server Administration' started by 501, Jun 2, 2007.

  1. #1
    How to prevent people from hotlinking anything on your server.

    You can stop servers from hotlinking your site's files by editing the .htaccess file in your site's root directory. (Consult your webhost on accessing your .htaccess file.)


    Example: Your site url is www.example.com. To stop hotlinking images from an outside domain and display an image called nohotlink.jpg instead, use this code in your .htaccess file:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/ [NC
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule .(jpe?g|gif|bmp|png)$ images/nohotlink.jpg [L]
    Code (markup):
    To allow hotlinking images only if the REFERER (sic) is from a specific directory from your domain:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/dir/ [NC
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule .(jpe?g|gif|bmp|png)$ images/nohotlink.jpg [L]
    Code (markup):
    To stop hotlinking images from specific outside domains only, named badsite.net and badsite.com:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^http://(www.)?badsite.net/ [NC,OR
    RewriteCond %{HTTP_REFERER} ^http://(www.)?badsite.com/ [NC
    RewriteRule .(jpe?g|gif|bmp|png)$ images/nohotlink.jpg [L]
    Code (markup):
    Warning: Do not use .htaccess to redirect image hotlinks to another HTML page or server that isn't your own (such as this web page). Hotlinked images can only be redirected to other images, not to HTML pages.

    Original Tutorial Cited From:
    .htaccess Tutorials

    Hope some of you find this useful! Do let me know!! ;)
     
    501, Jun 2, 2007 IP
  2. inworx

    inworx Peon

    Messages:
    4,860
    Likes Received:
    201
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Alternatively, you can use cPanel's HotLink function if you have it. Easy to use.
     
    inworx, Jun 3, 2007 IP