. Htaccess implements image anti-leech Protection

Source: Internet
Author: User

I am working on the IMG, Shouji, and daniu.

The method is as follows:

Add the following code to. htaccess:

 

RewriteEngine on
RewriteCond % {HTTP_REFERER }! ^ $ [NC]
RewriteCond % {HTTP_REFERER }! Yourdomain.com [NC]
RewriteCond % {HTTP_REFERER }! Zhuaxia.com [NC]
RewriteCond % {HTTP_REFERER }! Xianguo.com [NC]
RewriteCond % {HTTP_REFERER }! Google.com [NC]
RewriteCond % {HTTP_REFERER }! Bloglines.com [NC]
RewriteCond % {HTTP_REFERER }! Feedburner.com [NC]
RewriteCond % {HTTP_REFERER }! Feedsky.com [NC]
RewriteCond % {HTTP_REFERER }! Youdao.com [NC]
RewriteCond % {HTTP_REFERER }! Google.cn [NC]
RewriteCond % {HTTP_REFERER }! Google.com.tw [NC]
RewriteCond % {HTTP_REFERER }! Google.com. sg [NC]
RewriteCond % {HTTP_REFERER }! Google.com.hk [NC]
RewriteCond % {HTTP_REFERER }! Bloglines.com [NC]
RewriteCond % {HTTP_REFERER }! Soso.com [NC]
RewriteCond % {HTTP_REFERER }! Mail.qq.com [NC]
RewriteCond % {HTTP_REFERER }! Cn.bing.com [NC]
RewriteCond % {HTTP_REFERER }! Image.baidu.com [NC]
RewriteCond % {HTTP_REFERER }! So.360.cn [NC]
RewriteRule. *. (gif | jpg | png) $ http://yourdomain.com/no.png?r,nc,l]

Note: replace yourdomain.com with your own address. The second line and the last line must be different addresses.

Explain the preceding statement:

1. RewriteCond % {HTTP_REFERER }! ^ $ [NC]

Allow access with "HTTP_REFERER" Blank, that is, allow users to directly enter the image address in the browser address bar to display the image file.

In general, this is optional. However, we recommend that you set this parameter. If you force a request to have "HTTP_REFERER ",

It may cause some problems, such as when the user accesses the server through the proxy.

2. RewriteCond % {HTTP_REFERER }! Domain.com [NC]

Set the HTTP source that can be accessed, including the website itself, Google, Baidu, Bloglines, and Feedburner.

3. RewriteRule. *. (gif | jpg | png) $ http://yourdomain.com/no.png [R, NC, L]

Defines the images to be replaced when a chain is stolen, so that all the URLs of jpg, gif, and png files are displayed in the No. png file under the root directory.

Note: Do not place the displayed image in the anti-leech directory. The smaller the size of the image file, the better. Of course you can.

Instead of replacing the image, use the following statement:

RewriteRule. *. (gif | jpg | png) $-[F]

4. Describe the R, NC, and L

R means turning.

NC is case insensitive.

L indicates the end of this redirection. Subsequent redirection is not affected by the previous judgment statement.

5. file types to prevent leeching

In the preceding example, the files are gif, jpg, and png. You can change or add other file types as needed, such as rar and mov, with different file extensions.

Use "|" to separate them.

In this way, you can basically copy the leeching information and minimize the loss of server traffic.

No worries about traffic consumption. Of course, if you don't care about this traffic, you don't have to consider the above settings!

Function extensions:

RewriteRule. *. (gif | jpg) $ http://yourdomain.com/no.png [R, NC, L]

When a file with the jpg or gif extension is requested, if the referer field cannot match http: // * .yourdomain.com *

When this expression is used, the server returns a 302 status code and redirects it to http://yourdomain.com/no.png.

To increase traffic, we can also direct our website.

You only need

RewriteRule. *. (gif | jpg) $ http://yourdomain.com/no.png [R, NC, L]

Change

RewriteRule. *. (gif | jpg) $ http://yourdomain.com/[R, NC, L]

Related Article

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.