The ubuntu apache anti-leech method first enables the apache rewrite function:
Sudo vi/etc/apache2/sites-available/default modify the following Options FollowSymLinks AllowOverride None (change to AllowOverride All) Options Indexes FollowSymLinks MultiViews AllowOverride None (change to deny All) order allow, deny www.2cto.com allow from all and then perform apache rewrite and Add. htaccess RewriteEngine onRewriteCond % {HTTP_REFERER }! ^ $ [NC] RewriteCond % {HTTP_REFERER }! Nobing.cn [NC] RewriteCond % {HTTP_REFERER }! Google.com [NC] RewriteCond % {HTTP_REFERER }! Baidu.com [NC] RewriteCond % {HTTP_REFERER }! Bbs.jiazhuang8.com [NC] RewriteRule. * \. (gif | jpg) $ http://nobing.cn/no.png [R, NC, L] principle:
. The htaccess file will affect its directory and its sub-directories. Therefore, if the content we want to protect (This section uses anti-image leeching as an example, that is, images) is located in multiple directories on the website, you can consider placing the image in the root directory. If the image has a separate subdirectory such as "/images /", you only need to put it in this directory (of course, you can also put it in the root directory ). Note that if you upload the created. htaccess file to the server through FTP, the transmission mode should be ASCII, not Binary. After uploading to the server, you should change its properties to 644 or "RW-R-R-" Through CHMOD, so that the server can be used and cannot be modified through the browser, of course ,. the Readable attribute of htaccess also has a certain risk: attackers can use it to find the object you want to protect or the location of the authentication file-the solution is to authenticate the file. put htpasswd outside the root directory of the website, so that it cannot be found through the network. Use. htaccess disables leeching. htaccess is a simple method to prevent unauthorized links to non-Html files such as images, compressed files, or videos on websites. By adding a few commands to the file, we can protect our valuable bandwidth. For example, the settings of nobing.cn are as follows: www.2cto.com and below are referenced content: RewriteEngine onRewriteCond % {HTTP_REFERER }! ^ $ [NC] RewriteCond % {HTTP_REFERER }! Nobing.cn [NC] RewriteCond % {HTTP_REFERER }! Google.com [NC] RewriteCond % {HTTP_REFERER }! Baidu.com [NC] RewriteCond % {HTTP_REFERER }! Bbs.jiazhuang8.com [NC] RewriteRule. * \. (gif | jpg) $ http://nobing.cn/no.png [R, NC, L] briefly explain the above statements: 1. RewriteCond % {HTTP_REFERER }! ^ $ [NC] allows an empty "HTTP_REFERER" access, that is, allows 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" to access the service, this may cause some problems, for example, when the user accesses the service through the proxy server.
2. RewriteCond % {HTTP_REFERER }! Webeta.cn [NC] sets the HTTP source for access, including the website itself, Google, Baidu, bbs.jiazhuang8.com, and so on. 3. RewriteRule. *\. (gif | jpg | png) $ http://nobing.cn/no.png [R, NC, L] defines the image to be replaced when the chain is stolen, so that all the webpages that steal the chain jpg, gif, png and other files, the "PNG" file in the root directory is displayed. Note: Do not place the displayed image in the anti-leech directory. The smaller the size of the image file, the better. You can also use the following statement instead of replacing the image: RewriteRule. *\. (gif | jpg | png) $-[F] 4. Note that R, NC, and LR indicate the redirection meaning. www.2cto.com NC indicates the case-insensitive L indicates the end of The redirection, subsequent redirection is not affected by the previous judgment statement. 5. The file types that prevent leeching are gif, jpg, and png. You can change or add other file types as needed, for example, rar and mov. Different file extensions are separated by "|. In this way, we can basically prevent leeching and minimize the fearless consumption of server traffic.