Monday, July 11, 2011

Apache achieve a ban on image hotlinking

After the finish http://zlemon.com this image blog traffic is steadily rising, followed by hotlinking problems come, hotlinking is nothing, open for two days, traffic can not stand, so only chain needs to be a friend of external apologize: the
Apache implementation prohibits the use of image hotlinking:
Modify the httpd.conf configuration file:
SetEnvIfNoCase Referer "^ http://zlemon.com/"  local_ref = 1  
< FilesMatch . "(gif | jpg)" >  
Order Allow, Deny Allow from env = local_ref 
  FilesMatch >
This simple application can not only solve the problem of hotlinking images, also slightly modified to prevent hotlinking to download any file problems.
When using the above method specified host from the non-linked picture, the picture will not be displayed, if you want to display a "No hotlinking" of images, we can use mod_rewrite to achieve.
First, when installing apache with-enable-rewrite mod_rewrite module load parameters.
Assuming "No hotlinking" image for the abc.gif, we can be in the httpd.conf configuration:
RewriteEngine on RewriteCond % { HTTP_REFERER }  ! ^ $ RewriteCond % { HTTP_REFERER }  ! ^ HTTP: / / ( www \. ) ? zlemon.com / . * $ [ NC ]  
RewriteRule \. ( gif | jpg ) $ HTTP: / / zlemon.com / abc.gif [ R, L ]
ZLEMON configuration is as follows:
 
< VirtualHost * : 80 > 
    ServerName zlemon.com DocumentRoot / usr / local / Apache / htdocs / zlemon SetEnvIfNoCase Referer "^ http://zlemon.com/"  local_ref = 1  
    < FilesMatch . "(gif | jpg)" >  
    Order Allow , Deny Allow from env = local_ref 
      FilesMatch > 
 VirtualHost >