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

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




Stop hotlinking via referrer using .htaccess




This is a re-active approach to blocking hot linking websites. This is an approach where you are unaware of your user community however you are aware of bad referrer's. This method uses .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 "bad-referrer.com" with a bad domain.

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^http://www\.bad-referrer\.com [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\.bad-referrer\.com [NC]
      The above checks to see if the client was referrer to your website via "bad-referrer.com" to your own domain. If that client was then any image he/she tries to access will be replaced with an image of "bad.gif", else they will be allowed to your website.


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