ISAPI rewrite is really a good thing. We can not only use it to implement simple URL rewriting to implement a search engine-friendly (SEF) URL format, you can also use ISAPI rewrite to easily achieve server-side image load balancing, image anti-leech protection, and other web functions.
1. iis6.0 uses isapi_rewrite for image Load Balancing
Server environment:Windows Server 2003 + IIS 6.0 + isapi_rewrite 3.x
Previously, all images on the website were placed in a logical partition. As the website traffic increases, the disk load is a little too high. Therefore, I want to use isapi_rewrite to balance the image load.
Copy the singular image to The pictrue directory of the edisk. Copy the double number of images to The pictrue directory of drive F.
Create a new site in IIS. Create two virtual directories pointing to the PIC directory in the E disk and the PIC directory in the f disk respectively. The names are pictrue0 and pictrue1 respectively.
Rewirte rule:
# Helicon isapi_rewrite configuration file # version 3.1.0.58 rewriteengine on # Double pictruerewriterule pictrue/([0-9] +) _ ([0-9] + [02468]) \. (JPG | GIF | PNG | BMP | JPEG)/pictrue0/$1 _ $2. $3 [Nc] # signle pictruerewriterule pictrue/([0-9] +) _ ([0-9] + [13579]) \. (JPG | GIF | PNG | BMP | JPEG)/pictrue1/$1 _ $2. $3 [Nc]
Extended ideas:In other words, we can use the image Load Balancing Principle to achieve Load Balancing for file downloads. If we use the server disk moment for load balancing, the server throughput will be significantly improved, if you are interested, try it out.
2. Use isapi_rewrite to implement image anti-leech Protection
The leeching of images is unfortunate for webmasters. After being leeched by large-traffic websites, it will bring unnecessary burden to servers, seriously affecting the normal operation of websites. Websites with business models do not have to say anything about damages.
Image anti-leech has some solutions. Basically, the HTTP referer header is used for condition judgment. Using mod_rewrite in Apache can prevent image and other resources from being leeched. The following is an example of using mod_rewrite in Apache to prevent MP3 resources from being leeched. The modification also applies to anti-leech processing for images and other resources:
Rewriteengineon rewritecond % {http_referer }! ^ Http: // (www .)? Sky54 \. net /. * $ [Nc] rewriterule. (MP3 | RAR) $ http: // www \. sky54 \. net/archives/001 \. HTML [R = 301, l]
The above method is also applicable to static Web pages. In addition, scripts are used in dynamic web pages for anti-leech processing.
Today, we mainly talk about using isapi_rewrite in IIS for image anti-theft processing. Isapi_rewrite is a software developed by helicontech to convert URLs using regular expressions. Similar to mod_rewrite of Apache, isapi_rewrite is specially developed for Microsoft's IIS and is often used for static Web site applications.
I will not talk about how to install and use isapi_rewrite. The following describes how to use isapi_rewrite to process anti-leech protection for images and other resources.
Add the following rules to httpd. ini:
[Isapi_rewrite] rewritecond HOST: (. +) rewritecond Referer :(?! Http: // 1. *). * rewriterule .*.(? : GIF | JPG | PNG | JPEG | BMP)/block.gif [I, O]
Principle: Use the referer information returned by HTTP. If the address used by the Referer is not a local website, use block.gif images instead. A prompt or warning message can be added to block.gif to prevent image leeching.
3. Use isapi_rewrite to achieve permanent website redirection of 301
Using isapi_rewrite to achieve permanent website redirection in 301
301 redirection (301 redirect: permanently moved) indicates that the content is permanently transferred to the new URL, so that the search engine will know that the content has been transferred and will capture the new URL, so it is friendly. During domain name resolution, we will create an empty Host Name To facilitate users to enter the website address, while eliminating www. This facilitates users, but from the SEO perspective, the URL standardization rules are violated. Therefore, we need to perform 301 redirection on these inconsistent URLs.
301 redirection of site Domain Name
The following rules can be used to redirect sky54.net to www.sky54.net in 301, which is friendly for search engines.
Note:The following url rewrite rule, which is redirected to domain name 301 on this site, contains isapi_rewrite 2. X and isapi_rewrite 3. X version 2 rules. Make sure to confirm the version used by your server during use. Otherwise, it will not work. isapi_rewrite 3. version X provides an isapi_rewrite 2. convert the X rule to isapi_rewrite 3. X rule.
# For isapi_rewrite 2. xrewritecond HOST: ^ sky54 \. net $ rewriterule (. *) HTTP \: // www \. sky54 \. net $1 [I, RP] # For isapi_rewrite 3. xrewritecond % {http: Host} ^ sky54 \. net $ rewriterule (. *) HTTP \: // www \. sky54 \. net $1 [NC, r = 301]
301 permanent redirection between different domain names
When the second-level domain name is changed or the new domain name is changed, it is a pity that the traffic and weight of the old domain name will be lost in vain? With isapi_rewite, you can achieve 301 permanent redirection of the domain name, which can redirect the traffic and weight of the old domain name to the new domain name.
For example, use isapi_rewrite to permanently redirect the sky54.cn domain name to http://www.sky54.net/. the detailed rewrite rule is as follows:
# For isapi_rewrite 2. xrewritecond HOST: ^ sky54 \. CN $ rewriterule (. *) HTTP \: // www \. sky54 \. net $1 [I, RP] # For isapi_rewrite 3. xrewritecond % {http: Host} ^ sky54 \. CN $ rewriterule (. *) HTTP \: // www \. sky54 \. net $1 [NC, r = 301]
Tip:After isapi_rewrite 301 redirection, all file access under the domain name will be redirected, not just the Home Page!
301 permanent redirection between pages
When we change the addresses of some pages but do not want to lose traffic, we should use 301 redirection to redirect the original URL to the new URL, in this way, the search engine will know that the page address is changed and will not think that the page error disappears.
The rules are as follows:
# For isapi_rewrite 2. xrewriterule ^/ 404 \. htm $ http: // www \. sky54 \. net/index. PHP [I, O, RP, l] # For isapi_rewrite 3. xrewriterule ^/ 404 \. HTML $ http: // www \. sky54 \. net/Index \. PHP [NC, L, r = 301, O]
We redirect the 404.htm in the root directory to 301 in the form of a Forward (also in the form of/pagename) or a URL outside the site (starting with http ).
Note: Here, O indicates the URL is standardized, which may be used to process unicode encoded addresses (such as URLs containing Chinese characters) and querystring content. I have not tested it here. L indicates the last rule, and the last rule, that is, the subsequent rewrite rule, does not work for him, preventing confusion caused by re-rewriting of other matching rules.
The rewriterule used in this article is only applicable to ISAPI rewrite 2. X and 3. version X, because the identifier (such as [I, RP]) is not supported in versions earlier than 2.0, it will be in httpd. parse. an error is prompted in errors. If you are using an ISAPI rewrite version later than 3.0, then 2. the X rule is incompatible, but version 3.0 provides a rule converter. We can directly import the 2.0 rule, which will be automatically converted to version 3.0.
Read related recommendations:After reading isapi_rewrite application skills and methods, you can read URL rewriting: rewritecond instruction and rewriterule Instruction format to learn more about the principles of isapi_rewrite and rewrite rule Instruction format Syntax Parsing.