Use Apache's. htaccess to get anti-Leech protection

Source: Internet
Author: User
Apache. htaccess can implement many functions, such as password protection, prohibiting the display of directory lists, blocking/allowing specific IP addresses, and implementing 30 URLs

Apache. htaccess can implement many functions, such as password protection, prohibiting the display of directory lists, blocking/allowing specific IP addresses, and implementing 301 redirection of URLs. This article describes how to use Apache's. htaccess anti-Leech protection.
Of course, anti-leech can be solved by a program, such as PHP:

$ Referer = $ _ SERVER ['http _ referer']; $ selfurl = $ _ SERVER ['http _ host']; if (false = strpos ($ REFERER, $ selfurl) {echo 'phpddt. com to prevent illegal leeching '; exit (1 );}

Use Apache's. htaccess anti-Leech protection:
RewriteEngine OnRewriteCond %{HTTP_REFERER} !^$ [NC]RewriteCond %{HTTP_REFERER} !phpddt.com [NC]RewriteCond %{HTTP_REFERER} !google.com [NC]RewriteCond %{HTTP_REFERER} !baidu.com.com [NC]RewriteCond %{HTTP_REFERER} !feedburner.com [NC]RewriteCond %{HTTP_REFERER} !feedsky.com [NC]RewriteRule .*\.(rar|zip)$ http://www.phpddt.com/ [R,NC,L]

The. htaccess file will affect its directory and its subdirectories. You can put it in the root directory or sub-directory of the project.
The above code is also easy to understand:
RewriteCond % {HTTP_REFERER }! ^ $ [NC]
An empty source is allowed, that is, if the user's browser manually belongs to the source, files can be accessed.
RewriteCond % {HTTP_REFERER }! Phpddt.com [NC]
Allow access to the site itself. Similarly, access to Baidu, Google, and some subscription sources will be allowed later.
RewriteRule. * \. (rar | zip) $ http://www.phpddt.com/[R, NC, L]
Here, you can set the anti-Leech protection type. if you can jump to the homepage of a website, there is no anti-Leech protection for images on this site. if you do an anti-Leech protection for images, you can set an alternative image for the leeching:
RewriteRule. * \. (gif | jpg | png) $ http://phpddt.com/logo.png [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.