How to prevent Image leeching on the Apache server

Source: Internet
Author: User
This article mainly introduces how to prevent Image leeching on the Apache server and check the configuration of the. htaccess file. if you need it, refer to the following to explain anti-Leech and redirection:

What is the purpose of anti-Leech protection?

Prevent other websites from stealing your images and wasting your valuable traffic.

What is the purpose of image redirection?

If your website is dominated by images and the traffic will soon run out at the end of the month, you can use images to turn around without modifying the webpage, the image download request is redirected to another space (such as a trial host) for temporary transition.

For example, if your images are under the img Directory, place a file named. htaccess in the directory. the content is as follows:

  RewriteEngine on  RewriteCond %{HTTP_REFERER} !^$ [NC]  RewriteCond %{HTTP_REFERER} !simcole.cn [NC]  RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]  RewriteCond %{HTTP_REFERER} !google.com [NC]  RewriteCond %{HTTP_REFERER} !baidu.com [NC]  RewriteCond %{HTTP_REFERER} !bloglines.com [NC]  RewriteRule .(jpg|gif|png|bmp|swf|jpeg) /image/replace.gif [R,NC,L]  RewriteRule ^(.*)$ http://image.simcole.cn/image/$1 [L]

Below is a rough explanation:

  RewriteCond %{HTTP_REFERER} !^$ [NC]  RewriteCond %{HTTP_REFERER} !simcole.cn [NC]  RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]  RewriteCond %{HTTP_REFERER} !google.com [NC]  RewriteCond %{HTTP_REFERER} !baidu.com [NC]  RewriteCond %{HTTP_REFERER} !bloglines.com [NC]

This part is to determine whether or not to steal the chain. if the above conditions are true (that is, the request to access the image is neither directly entering the URL nor from simcole.cn, nor from zhuaxia.com or google.com, or from baidu.com or bloglines.com:

  

RewriteRule .(jpg|gif|png|bmp|swf|jpeg) /image/replace.gif [R,NC,L]

This means that all webpages with jpg, gif, png, bmp, swf, and jpeg files under the img directory are replaced by replace.gif images under the image directory. Note that do not place the displayed images in the img directory with anti-Leech settings. If the image request is not leeching based on the above rules, perform the following redirection:

  RewriteRule ^(.*)$ http://image.simcole.cn/image/$1 [L]

It means that all the requests under the img directory are directed to the target server, for example, there is a picture that the original url is a http://www.bebecn.com/img/girl.jpg, and now it will go to the http://image.bebecn.com/image/girl.jpg. Of course, you must copy all the files under the img Directory of the original server to the image directory of the temporary server to make the switch available. The effect is to save all the traffic occupied by image downloads on the original server, so that the temporary server can afford it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.