IIS anti-theft chain ISAPI rewrite picture anti-theft chain rule Writing _ Server other

Source: Internet
Author: User
Through g.cn and b.cn search after a number of different schemes, such as Web site program URL Camouflage method, server-side charging plug-in method and Isapi-rewrite rules filtering method, consider their own web site structure and wallet difficult problems, finally chose the latter, That is now popular to do pseudo static ISAPI rewrite writing rules to achieve my anti-theft chain "dream."

Why do you say it's a dream? First of all, I am sorry, lazy people I searched a lot after countless times to reprint the article, the present application of the code found that either does not work at all, or the effect is not up to what I want, after a few twists and turns after the original thought can easily learn to copy the chain of anti-theft to complete, hate those who will only reprint and false original webmaster, They are not to try to fill, how many people waste a lot of time.

The following ISAPI rewrite has been working on my server after a tutorial on bad corrections and changes to the rules left by predecessors.

After testing four kinds of normal situation, that is, the site links normal, white list of links normal, hotlinking link screen, search engine links normal.
in detail as follows;
one, completely shielding all hotlinking source of the writing (if there are other rules, it is placed above the existing rules)
Code:
Copy Code code as follows:

Rewritecond Host: (. +)
Rewritecond Referer: (?!) http://\1.*). *
Rewriterule. *\. (?: gif|jpg|jpeg|png|bmp)/block.gif [I,o,n]


Boss, here's a pee:
The first line uses the Rewritecond host to define the scope of the request host to which the rules under it apply.
The second line uses the Rewritecond referer to define the request source address that the rule applies to, and we all know that any Internet access to the site will leave traces of referer, as we have seen in the IIS log. Here's (?!) http://\1.*). * Means to judge all requests sent through HTTP semantics, apply the rule.
The third line through the Rewriterule definition anti-theft chain file suffix, here is only a picture suffix, you need to add mp3,rar and other all suffixes. The/block.gif in the back indicates that if the file being hotlinking after the suffix is turned, here is the block.gif of the root directory, which can be any file such as HTML. If you just want the file below a folder to be hotlinking, just add the path. For example, do not want to images and the PIC directory under the file is stolen, but other can. will be rewritten as:
Rewriterule (/images/|/pic/). *\. (?: gif|jpg|jpeg|png|bmp)/block.gif [I,o,n]
This situation is mainly some webmaster in others friendship links in the picture address is in their own this.
The [i,o,n],i representation of the last face is case-insensitive, O indicates that the URL is standardized, it may be used to handle Unicode-encoded addresses (for example, URLs containing Chinese), and the contents of QueryString, N means to request files from the site rather than to read the files from the local cache. The goal is to prevent users from visiting the site of your chain, and then back to your site also appear hotlinking prompts.
Hint, because this rule is through referer to get the address with http://words to filter, so it can not prevent other protocol hotlinking, such as thunder download. But through any browser direct access, as long as the HTTP is justified, through the kill.
The above about the role of Rewritecond and Rewriterule is only my own way of understanding, welcome in this regard a friend of professional research in the comments, so as to avoid misleading, in addition, if you encounter the Isapi-rewrite version of the problem, as long as the following regular formula is correct.
Ii. Elimination of the anti-theft chain
Code:
Copy Code code as follows:

Rewritecond Host: (. +)
Rewritecond Referer: (?!) http://\1.*). *
Rewritecond Referer: (?!) http://(. *) (\.baidu\.com|\.google\.com|\.google\.cn|\.g\.cn|\.gougou\.com|\.soso\.com|\.sogou\.com|\.youdao\. com|\.bing\.com|\.yahoo\.com|\.yahoo\.cn|\.eojoo\.com)). *
Rewriterule. *\. (?: gif|jpg|jpeg|png|bmp)/block.gif [I,o,n]

Boss, here's a pee:
First line ditto
Second line ditto
The third line filters through a regular expression of the request in the second row, which, by way of the above, filters out all the popular search engines, including your own station, or other stations on your server. Each of the different domain names is \.baidu\.com, many have the | number separated. If it is IP then write 100\.100\.100\.100
Line four, Ibid.
This explanation should not be difficult to understand it, directly to use, according to the original format change.
Regular expression symbol pee that appears in the rule:
. Represents a match for any character other than a line break
+ indicates that the preceding character can appear one to any number of times
* indicates that the preceding character can appear 0 to any number of times
() represents an expression group that can be understood together with the subtraction method
?! Indicates that the character following this symbol is not followed by a match if it appears
\ represents an escape symbol, such as the one in the URL. is a built-in operation symbol, which is to be escaped by \ to a character.
| To indicate or to connect a variety of possible
Through the above "messy" symbol, unexpectedly composed of such a strong rule, sigh!

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.