WarpZero RSS WarpZero@Twitter WarpZero@LinkedIn Michael Marth@Facebook Monday, 21-May-2012 01:45:59 EDT
   
warpzero.com

° Home
° News & Updates
° Howto & Knowledge Base
° External Resources
° Contact us
° Search
° Site Validated
° Site Map




Allow hot linking via referrer from specific domains




Allow hot linking to your images by creating a defined list of Good Referrers (or known good domains) by using .htaccess with RewriteRules.




  1. Ensure that the following parameters have been enabled within the apache configuration.

    Options FollowSymLinks
    AllowOverride FileInfo AuthConfig Limit

  2. If you have a separate configuration for your "images" and "htdocs" directory be sure to enable the above features in each section otherwise the .htaccess will not work.

    < Directory "/web/www_root/images">
    Options FollowSymLinks
    AllowOverride FileInfo AuthConfig Limit
    Order allow,deny
    Allow from all
    < /Directory>

    < Directory "/web/www_root/htdocs">
    Options FollowSymLinks
    AllowOverride FileInfo AuthConfig Limit
    Order allow,deny
    Allow from all
    < /Directory>

  3. Restart the webserver

    ./apachectl restart

  4. Create an .htaccess file within your "images" directory structure. Replace "domain.com" with your domain name.

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

    • RewriteEngine On
      If the "RewriteEngine" is not enabled these policies will not work.
    • RewriteCond %{HTTP_REFERER} !^http://www\.domain\.com [NC]
      The above checks to see if the client is from your own domain. If not then the second "RewriteCond" takes effect
    • RewriteCond %{HTTP_REFERER} !^$ [NC]
      The above checks to see if the client accessed your site directly.
    • RewriteRule \.(jpe?g|gif|bmp|png)$ images/bad.gif [L]
      If none of the "RewriteCond" conditions match then the client will be served the "bad.gif" image.

  5. If you have multiple domains which are allowed to use your images, be sure to include those domains in the policy otherwise they will all get the "bad.gif" image.

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://www\.yahoo\.com [NC]
    RewriteCond %{HTTP_REFERER} !^http://www\.google\.com [NC]
    RewriteCond %{HTTP_REFERER} !^http://www\.domain\.com [NC]
    RewriteCond %{HTTP_REFERER} !^$ [NC]
    RewriteRule \.(jpe?g|gif|bmp|png)$ images/bad.gif [L]

    • RewriteCond %{HTTP_REFERER} !^http://www\.yahoo\.com [NC]
    • RewriteCond %{HTTP_REFERER} !^http://www\.google\.com [NC]
      These lines indicate that "www.yahoo.com" and "www.google.com" are within your good list and that they are able to hot link to your image.


Linux Counter
Apache
IBM Canada
Cisco Systems
RedHat
Linux
 
 Published: Wednesday, 10-Nov-2010 05:05:54 EST