How to prevent picture hotlinking under Apache server, _php tutorial

Source: Internet
Author: User

Apache server to prevent the picture hotlinking method,


First explain a chain of anti-theft and steering:

What is the use of image anti-theft chain?

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

What is the use of picture steering?

If your site to picture-based, which day to find that the end of the traffic is almost exhausted, then you can use the picture to turn, in the premise of not modifying the page, the picture download request to other space (such as trial host), temporary transition.

Let's start by explaining that your pictures are in the IMG directory, and then drop a file named. htaccess in that directory, as follows:

Rewriteengine on Rewritecond%{http_referer}!^$ [NC] Rewritecond%{http_referer}!simcole.cn [NC] RewriteCond%{HTTP_R Eferer}!zhuaxia.com [NC] Rewritecond%{http_referer}!google.com [NC] Rewritecond%{http_referer}!baidu.com [NC] Rewr Itecond%{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]

Probably explained below:

Rewritecond%{http_referer}!^$ [NC] Rewritecond%{http_referer}!simcole.cn [NC] Rewritecond%{HTTP_REFERER}!zhuaxia.c Om [NC] Rewritecond%{http_referer}!google.com [NC] Rewritecond%{http_referer}!baidu.com [NC] Rewritecond%{HTTP_REF Erer}!bloglines.com [NC]

This part is judged whether hotlinking, if the above conditions are set up (that is, the request to access the picture, neither directly enter the URL, Nor is it from simcole.cn, nor from zhuaxia.com, nor from Google.com, nor from baidu.com, nor from Bloglines.com, to perform the following turns:

  

Rewriterule. (jpg|gif|png|bmp|swf|jpeg)/image/replace.gif [r,nc,l]

This means that all pages of JPG, GIF, PNG, BMP, SWF, JPEG files in the hotlinking img directory are replaced with replace.gif images in the image directory. Note Replace the displayed picture not in the IMG directory where the anti-theft chain is set. If the image request is not hotlinking according to the rules above, the following turns are performed:

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

This means that all requests to the IMG directory are directed to the target server, such as having a picture of the original URL is http://www.bebecn.com/img/girl.jpg, and will now go to http://image.bebecn.com/image/ Girl.jpg go. Of course, you have to first copy the files from the original server IMG directory to the image directory of the temporary server, and the steering is really available. The effect is to the original server image download the consumption of all the savings, so that the temporary server to bear.

http://www.bkjia.com/PHPjc/1027491.html www.bkjia.com true http://www.bkjia.com/PHPjc/1027491.html techarticle Apache server to prevent pictures hotlinking approach, first explain a chain of anti-theft and steering: Picture of what anti-theft chain to prevent other sites to steal your pictures, waste your valuable traffic ...

  • 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.