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]