Preventing Hotlinking!

Discussion in 'Search Engine Optimization' started by 501, Mar 20, 2007.

  1. #1
    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]
    PHP:
    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]
    PHP:
    To continue reading this tutorial to your own benefit, please visit

    Preventing Hotlinking

    Cheers! :)
     
    501, Mar 20, 2007 IP