Php uses htaccess to implement anti-leech Protection

Source: Internet
Author: User
For example, if all your images are in the img directory, place a file named. htaccess in the directory with the following content: RewriteEngineonRewriteCond % {HTTP_REFERER }! ^ $ [NC] RewriteCond % {HTTP_REFERER }! Simcole.cn [NC] RewriteCond % {HTTP_REFERER }! Zhuaxia.com [NC] RewriteCond % {

For example, if all your images are in the img directory, place a file named. htaccess in the directory with the following content: RewriteEngine on RewriteCond % {HTTP_REFERER }! ^ $ [NC] RewriteCond % {HTTP_REFERER }! Simcole.cn [NC] RewriteCond % {HTTP_REFERER }! Zhuaxia.com [NC] RewriteCond % {

For example, if all your images are in the img directory, place a file named. htaccess in the directory with the following content:

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://web.chinaitlab.com/UploadFiles_5817/200808/20080805094642297.jpg, And now it will go to the http://image.simcole.cn/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.

Isn't it easy? Try 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.