Apache anti-leech protection (image/file) Methods

Source: Internet
Author: User

This article introduces the anti-leech method. Here we use apache and apache. htaccess-based apache image anti-Leech and file anti-leech instances.

If you have your own server, first modify the./conf/httpd. conf file as follows:
Find # LoadModule rewrite_module modules/mod_rewrite.so
Remove the previous #
Change AllowOverride None to AllowOverride All.
Restart Apache2 server
Next, create a. htaccess file. The content of the. htaccess file is

The Code is as follows: Copy code
RewriteEngine on
RewriteCond % {HTTP_REFERER }! ^ [Url] http://test.com.ru/.#/url?#$ [NC]
RewriteCond % {HTTP_REFERER }! ^ [Url] http://test.com.ru $ [/url] [NC]
RewriteCond % {HTTP_REFERER }! ^ [Url] http://www.test.com.ru/.#/url?#$ [NC]
RewriteCond % {HTTP_REFERER }! ^ [Url] http://www.test.com.ru $ [/url] [NC]
RewriteRule. *. (jpg | jpeg | gif | png | bmp | rar | zip | exe) $
[Url = http://down.test.com.ru/err.html?http://down.test.com.ru/err.html#/url]
[R, NC]

The colored items must be changed to yours:
RED: You provide the download page address, that is, you can only download the provided stuff through this address.
Blue: To protect the file extensions (separated by |), that is, files with these extensions can only be accessed through red addresses.
Green: if you do not use a red address to access files with blue extensions, the system redirects back to the green address.
The next step is how to use the. htaccess file to implement anti-leech.
First, you need to create two directories in the space (of course, the directory name is yours), one for the web and the other for the down,
The web is used to download pages (or download programs), and down is of course the stuff you provide,
Change the red part of the. htaccess file to http: // your domain name/web. Blue part
Change to the file extension you want to protect. Change the green part to http: // your domain name/web. Save after modification


Htaccess anti-leech is simple and quick.

First, create a. htaccess file (generally an Apache server in linux), write the following code, and upload it to the root directory of the website:
 

The Code is as follows: Copy code

RewriteEngine on

RewriteCond % {HTTP_REFERER }! ^ $ [NC]

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

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

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

RewriteCond % {HTTP_REFERER }! Www.hihi123.com [NC]

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

 

Note:

The above uses my website www.hzhuti.com as an example to set up the HTTP source that can be accessed in turn, including our site itself, google.com, baidu.com, which is easy to collect and can be added to more websites, copy and modify multiple rows.

The last line of code is the anti-leech extension, add your own modifications; http://www.hzhuti.com

The location is usually in/usr/local/apache/conf/httpd. conf
Or apache 2.2/usr/local/apache2/conf/extra/httpd-vhost.conf
Add

The Code is as follows: Copy code
SetEnvIfNoCase Referer "^ http://www.ccvita.com" local_ref = 1
SetEnvIfNoCase Referer "^ http://ccvita.com" local_ref = 1
<Filesmatch ". (txt | doc | mp3 | zip | rar | jpg | gif)">
Order Allow, Deny
Allow from env = local_ref
</Filesmatch>

Here, your url is in bold. If there are multiple URLs, add multiple lines.
The italics are the suffix of the files that you need to anti-leech protection, separated by |


Another method is to use regular expressions, which are common in apache of different versions.
Statement:

The Code is as follows: Copy code
SetEnvIfNoCase Referer "^ <strong> http: //. * .yourdomin.com </strong>" local_ref = 1 SetEnvIfNoCase Referer "<strong>. * .yourdomin.com </strong>" local_ref = 1
<Filesmatch ". (txt | doc | mp3 | zip | rar | jpg | gif)">
Order Allow, Deny
Allow from env = local_ref
</Filesmatch>

The bold part has a difference. It is written in regular expressions, and symbols represent escaping, because. itself has its own role in regular expressions.

The above is the use of Apache anti-leech protection. For Apache anti-leech cracking, it is simple to say that Apache anti-leech is used to determine whether users are leeching. If you write your own collection program, we can use CURLOPT_REFERER and CURLOPT_USERAGENT in the curl_setopt function of php to simulate referer and useragent.

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.