How to use the. htaccess anti-theft chain website Picture _php Tutorial

Source: Internet
Author: User
Anti-theft chain site pictures as the name implies is to prevent external sites to steal our site pictures, its role is to prevent other people in other blogs, space sites affixed to the image of our site so that visitors do not enter our site, but it is still consuming the traffic of our website space. Isn't that very unpleasant? OK, so let's take a look at how to use. htaccess to prevent others from hotlinking pictures of our website!

Using the. htaccess to the anti-theft chain picture is actually very simple, as long as you understand. htaccess rules, it's just one thing. Let's look at 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]

Here is a detailed explanation of the above code:

Rewriteengine on

URL Rewrite engine switch, if set to off, any rewrite rule definition will not be applied, another advantage of the switch is that if in order to temporarily remove the rewrite rules, then turn off and then restart Apache, do not have to comment out the following the rules of the rewrite rule. Note that this statement is written as far as possible on the first line of the file.

Rewritebase/

The function of this statement is if the part is rewritten in the following Rewriterule definition (file name index.html here). If there is no previous/, then the relative directory. Generally directly set to/meaning is the root directory.


Rewritecond%{http_referer}!^$ [NC]

Allow access via an empty "http_referer", that is, when the user enters the image address directly in the browser address bar, the slice can be displayed. In general, this is optional, however, it is recommended to do so, or if forcing must have "http_referer" to be accessible, there may be some problems, such as when the user is accessed 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 are the HTTP sources that are allowed to access, including our own websites, google.com, baidu.com, sogou.com, soso.com, youdao.com, and yahoo.cn. This is also to let the search engine can normally crawl our site pictures to consider.

Rewriterule. *\. (gif|jpg|png|bmp) $ http://www.phpernote.com/change.gif [r,nc,l]

OK, here is the rules for setting up the anti-theft chain. Here the setting is to let all hotlinking this site jpg, GIF, PNG, BMP and other picture files of the Web page, all display to http://www.phpernote.com/change.gif this file replacement display. It is important to note that replacing the displayed picture is not placed in the directory where the anti-theft chain is set or in the directory where the anti-theft chain is set, and the smaller the picture file is, the better. Of course, you can also not set a replacement image, using the following rules, Hotlinking's website will show a blank picture

Rewriterule. *\. (gif|jpg|png|bmp) $–[f]

Also, if you do not understand the meaning of the NC F L character in the brackets after the above rule, please refer to this site:. htaccess Syntax Parameter description

Well, after the above settings, all hotlinking your website image file site, will be because of this unfriendly display and give up hotlinking, this to some extent, reduce your space server unnecessary traffic, is a worthwhile thing to do.

Articles you may be interested in

    • Htaccess how to set up a picture of a directory in an anti-theft chain
    • Use. htaccess to deny an IP access to a Web site
    • Use Apache htaccess to prevent images from being hotlinking
    • Using the. htaccess Block List Directory
    • 10 sections of practical. htaccess Code Snippets
    • Set the site default home page by. htaccess
    • How to modify the site default home page by. htaccess?
    • PHP uses curl to implement multi-threaded classes, php curl multithreading download pictures

http://www.bkjia.com/PHPjc/764200.html www.bkjia.com true http://www.bkjia.com/PHPjc/764200.html techarticle anti-theft chain website image as the name implies is to prevent the external site misappropriation of our site pictures, its role is to prevent other people in other blogs, space sites affixed to our site map ...

  • 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.