How to use. htaccess anti-leech website Images

Source: Internet
Author: User

Anti-leech website images, as the name implies, are used to prevent external websites from stealing images of our websites. They are used to prevent others from posting images on other blogs, the space website is pasted with images of our website, causing visitors to not access our website, but it still consumes the traffic of our website space. Is this really uncomfortable? Now let's take a look at how to use. htaccess to prevent others from leeching our website's images!

The use of. htaccess to anti-leech images is actually very simple, as long as you understand the. htaccess rules, it is also a sentence. Here is a complete example:

RewriteEngine OnRewriteBase /RewriteCond %{HTTP_REFERER} !^$ [NC]RewriteCond %{HTTP_REFERER} !phpernote.com [NC]RewriteCond %{HTTP_REFERER} !google.com [NC]RewriteCond %{HTTP_REFERER} !baidu.com [NC]RewriteCond %{HTTP_REFERER} !sogou.com [NC]RewriteCond %{HTTP_REFERER} !soso.com [NC]RewriteCond %{HTTP_REFERER} !youdao.com [NC]RewriteCond %{HTTP_REFERER} !yahoo.cn [NC]RewriteRule ^uploadfiles/(.*)\.(gif|jpg|png)$ http://www.phpernote.com/images/loading.gif [L]

The following code provides a detailed explanation:

RewriteEngine On

The url rewrite engine switch. If it is set to off, any rewrite rule definition will not be applied. Another advantage of this switch is that to temporarily remove the rewrite rule, switch to off and restart Apache. The following rewrite rules cannot be commented out. Note that this statement should be written in the first line of the file as much as possible.

RewriteBase/

The syntax of this sentence is the document name index.html if it is re-written in the following rewriteruledefinition ). If no/exists, it is a relative directory. Generally, the root directory is directly set.


RewriteCond % {HTTP_REFERER }! ^ $ [NC]

Allow access by using an empty "HTTP_REFERER", that is, when the user directly enters the image address in the browser address bar, the picture can be displayed. In general, this is optional. However, we recommend that you set it as above. Otherwise, some problems may occur if you force "HTTP_REFERER" to be available for access, for example, when a user accesses an instance through a proxy server.

RewriteCond % {HTTP_REFERER }! Phpernote.com [NC]
RewriteCond % {HTTP_REFERER }! Google.com [NC]
RewriteCond % {HTTP_REFERER }! Baidu.com [NC]
RewriteCond % {HTTP_REFERER }! Sogou.com [NC]
RewriteCond % {HTTP_REFERER }! Soso.com [NC]
RewriteCond % {HTTP_REFERER }! Youdao.com [NC]
RewriteCond % {HTTP_REFERER }! Yahoo.cn [NC]

Here, we set the HTTP source for access, including our own website, google.com, baidu.com, sogou.com, soso.com, youdao.com, and yahoo.cn. This is also for the search engine to capture our website images.

RewriteRule. * \. (gif | jpg | png | bmp) $ http://www.phpernote.com/change.gif [R, NC, L]

OK. Here is the anti-leech rule. Here the settings is to all the chain of the website jpg, gif, png, bmp and other image files of the web page, will be displayed in http://www.phpernote.com/change.gif this file instead of display. Note: Do not place the displayed images in the anti-leech setting directory or in the anti-leech setting directory. The smaller the size of the image file, the better. Of course, you can also choose not to replace images. Use the following rules to display a blank picture of a leeching website.

RewriteRule. * \. (gif | jpg | png | bmp) $-[F]

In addition, if you do not understand the meaning of the nc f l character in the brackets following the above rules, please refer to this site:. htaccess syntax parameter description

All right, after the above settings, all the websites that steal the images and files of your website will give up the leeching because of this unfriendly display, this reduces unnecessary traffic on your space server to a certain extent and is worth doing.

 

Articles you may be interested in
  • . Htaccess: how to set images in a directory of anti-leech
  • Using. htaccess to deny access to a website from an ip address
  • Use Apache htaccess to prevent image leeching
  • Disable the list directory using. htaccess
  • 10 practical. htaccess code snippets
  • Set the default homepage of a website through. htaccess
  • How does one modify the default homepage of a website through. htaccess?
  • Php uses curl to implement multi-threaded classes and php curl to download images with multiple threads

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.