. Htaccess configuration file implements anti-Leech protection for website file images

Source: Internet
Author: User
Tags file url

Use rewrite to enable the mode_rewrite module of apache to support the server. set the permission for the htaccess file directory, and add it to the root directory of the website. the htaccess file determines whether the referer is the address of this site. All files from non-local address referer are directed to a new webpage or prompt webpage. You can easily set anti-Leech protection using the. htaccess file!

Based on the settings below, you can easily prevent file leeching and minimize server traffic consumption!

The content of the. htaccess file is as follows:

The code is as follows: Copy code


<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond % {HTTP_REFERER }! ^ $ [NC]

RewriteCond % {HTTP_REFERER }! 111cn.net [NC]

RewriteRule. *. (gif | jpg | png | swf) $ yun_qi_img/daolian.png [R, NC, L]

</IfModule>

The above code is to prevent Baidu and other seo/seo.html "target =" _ blank "> Search Engines. We can add them.

The code is as follows: Copy code

RewriteEngine on

RewriteCond % {HTTP_REFERER }! ^ $ [NC]

RewriteCond % {HTTP_REFERER }! Sudu.cn [NC]

RewriteCond % {HTTP_REFERER }! Baidu.com [NC]

RewriteCond % {HTTP_REFERER }! Google.cn [NC]

RewriteCond % {HTTP_REFERER }! Bloglines.com [NC]

RewriteCond % {HTTP_REFERER }! Feedburner.com [NC]

RewriteCond % {HTTP_REFERER }! Feedsky.com [NC]

RewriteRule. *. (gif | jpg) $ http://www.111cn.net/no.png [R, NC, L]

. Htaccess file code parsing:

RewriteEngine On: enable Rewrite module

RewriteCond % {HTTP_REFERER }! ^ $ [NC]: allow blank url sources. Users can directly enter the file URL for access. If you do not want users to directly enter the URL for access, delete this line of code!

RewriteCond % {HTTP_REFERER }! Jannn.com [NC]: the URL that can be accessed. You can add the URL in the same format as needed. Replace the URL with the URL that can be accessed!

The code is as follows: Copy code

RewriteRule. *. (gif | jpg | png) $ http://www.111cn.net/daolian.png [R, NC, L]:

The extension names of the files to prevent leeching are separated by the symbol "|", for example, adding | mp3 | swf | exe. The following URL is, the address returned to the leeching user when an error occurs. This is changed based on the actual application. For example, if you want to prevent images from leeching, you can return a designed copyright picture to the leeching webpage! For example, if you want to prevent leeching from MP3 files, you can return a copyright record of your own to the leeching webpage! You can also directly change it to your website address to import all traffic to your website!

Description: R, NC, and L

R means turning.

NC is case insensitive.

L indicates that the current redirection ends, and subsequent redirection is not affected by the previous judgment statement.

5. File types to prevent leeching

In the preceding example, gif, jpg, and png are used. You can change or add other file types, such as rar and mov, as needed. Different file extensions are separated by "|.

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.