What is URL rewrite )?
URL rewriting is the process of redirecting incoming Web requests to other URLs.
For example, when a browser sends a request http://www.test.com/tags/, the server automatically redirects the request to http://www.test.com/tags.asp
We know that there is mod_rewrite in Apache to implement the URL rewrite function (URL rewrite). However, IIS does not provide this function, so we need to use a third-party component. In fact, there are several rewirte components under IIS, all of which are loaded through ISAPI filters and then URL rewriting.
ISAPI rewrite is widely used. This component is basically used in Windows Website spaces that support the rewirte function in China. The ISAPI rewrite component is available in both the free and commercial versions. The free version only supports global httpd. ini configuration (each site cannot be configured separately unless it is implemented by loading different DLL files .) The commercial version allows you to customize the httpd. ini file, which takes effect only in the root directory of the site. This greatly facilitates the user to modify the URL rewrite rules.
ISAPI rewrite is a powerful URL Processing Engine Based on regular expressions. It is basically like Apache's mod_rewrite, but it is dedicated to Microsoft's Internet Information Server (IIS) designed.
ISAPI rewrite is an ISAPI filter written in pure C/C ++, so the speed is quite fast! ISAPI rewrite allows you to freely plan website URLs.
ISAPI is called Internet server application program interface.
ISAPI rewrite 2 Product address: http://www.isapirewrite.com/
ISAPI rewrite 3 product address: http://www.helicontech.com/isapi_rewrite/
The main feature of version 3.0 is that it supports using the Apache. htaccess file to use mod_rewrite in IIS. This feature eliminates the difference between IIS and Apache in the rewrite of daily applications.
Httpd. ini file example
[Isapi_rewrite]
# This is a comment
#300 = 5 minutes
Cacheclockrate 300
Repeatlimit 20
# Block external access to the httpd. ini and httpd. parse. Errors files
Rewriterule/httpd (? :. Ini |. parse. Errors)/[F, I, O]
# Block external access to the helper ISAPI extension
Rewriterule. *. isrwhlp/[F, I, O]
# Some M rules
Rewritecond HOST: (. +)
Rewritecond command
Syntax :( syntax) rewritecond testverb condpattern [flags]
This command defines a condition rule, and pre-runs the rewritecond command before the rewriterule, rewriteheader, or rewriteproxy command. The following rule only has its, the pattern matches the current status of the URI and the additional conditions are also applied.
Testverb
Specifies verb that will be matched against regular expression.
The expression defined in the verb matching rule.
Testverb = (URL | method | version | httpheadername: | % servervariable) where:
URL-returns request-Uri of client request as described in RFC 2068 (HTTP 1.1 );
Returns the request-Uri of the requirement described by the client in rfc2068.
Method-returns HTTP Method of client request (options, get, Head, post, put, delete or trace );
Return the HTTP method required by the client (options, get, Head, post, put, delete or trace)
Version-returns HTTP version;
Return HTTP Version
Httpheadername-returns value of the specified HTTP header. httpheadername can be any valid HTTP header name. header names shoshould include the trailing colon ":". if specified header does not exists in a client's request testverb is treated as empty string.
Returns the value of the HTTP header file.
Httpheadername =
Accept:
Accept-charset:
Accept-encoding:
Accept-language:
Authorization:
COOKIE:
From:
Host:
If-modified-since:
If-match:
If-None-match:
If-range:
If-unmodified-since:
Max-forwards:
Proxy-authorization:
Range:
Referer:
User-Agent:
Any-custom-Header
For more information about HTTP header files and their values, see rfc2068.
Servervariable returns the value of the server variable defined by this parameter. For example, for the server port, the list of all server variables should be established in the IIS documentation, and the variable name should be prefixed with the % character;
Condpattern
The regular expression to match testverb
Rule expression matches testverb
[Flags]
Flags is a comma-separated list of the following flags:
O (normalize)
Normalizes string before processing. Normalization nodes removing of an URL-encoding, illegal characters, etc. This flag is useful with URLs and URL-encoded Headers
Rewriterule command
Syntax: rewriterule pattern formatstring [flags]
This command can occur more than once. Each Command defines a separate rewrite rule. The definition commands of these rules are very important, because this command is useful when applying runtime rules.
I (ignore case)
This flag affects the rewriterule command and the corresponding rewritecond command regardless of case.
F (Forbidden)
Respond to the client, stop the rewriting process, and send the 403 error. Note that in this case, formatstring is useless and can be set to any non-null string.
L (last rule)
Stop the rewrite process here without applying any rewrite rules. Use this flag to prevent the currently overwritten URI from being overwritten again by the subsequent rules.
N (next iteration)
Force rewritingengine to adjust the rule target and restart the rule from scratch (all modifications will be saved). The number of reboots is limited by the value specified by repeatlimit. If this value exceeds n flag, it will be ignored.
NS (Next iteration of the same rule)
Restart the rule process (for example, force repeated rule application) from the same rule with N, and use the repeatlimit command to specify the maximum number of rules that are repeatedly implemented,
P (Force proxy)
Force the target URI to be a proxy internally and immediately scale up to cope with proxy requirements through ISAPI. Make sure that the proxy string is a valid Uri, including the Protocol host, or else the proxy will return an error.
R (explicit redirect)
Forces the server to send a redirection to the client to immediately respond and provide a new address of the destination URI. The redirection rule is often the final rule.
RP (permanent redirect)
It is almost the same as the [R] flag, but the 301http status code is released instead of the 302http status code.
U (unmangle log)
Uri is recorded when the URI is a source requirement rather than a rewrite Requirement
O (normalize)
Standardize the string before implementation. Standardization includes URL-ENCODING, invalid character re-movement, etc. This tag is useful for URLs and URLS-ENDODED Headers
CL (case lower)
Lowercase
Cu (Case upper)
Uppercase
Rewriteheader Directive
Syntax: rewriteheader headername pattern formatstring [flags]
This command is a more general variant of rewriterule. It not only overrides the client requirement of the URL, but also overwrites the HTTP header. This command is not only used for rewriting. Generate, delete any HTTP headers, and even change the client request Method
Headername
Specifies the customer header to be overwritten. The value is the same as the testverb parameter in the rewritecond command.
Pattern
Restrict rule expressions to match request-Uri,
Formatstring
Specify the formatstring of the new Uri.
[Flags]
Is a command separation list of the following flags
I (ignore case)
This flag affects the rewriterule command and the corresponding rewritecond command regardless of case.
F (Forbidden)
Respond to the client, stop the rewriting process, and send the 403 error. Note that in this case, formatstring is useless and can be set to any non-null string.
L (last rule)
Stop the rewrite process here without applying any rewrite rules. Use this flag to prevent the currently overwritten URI from being overwritten again by the subsequent rules.
N (next iteration)
Force rewritingengine to adjust the rule target and restart the rule from scratch (all modifications will be saved). The number of reboots is limited by the value specified by repeatlimit. If this value exceeds n flag, it will be ignored.
NS (Next iteration of the same rule)
Restart the rule process (for example, force repeated rule application) from the same rule with N, and use the repeatlimit command to specify the maximum number of rules that are repeatedly implemented,
R (explicit redirect)
Forces the server to send a redirection to the client to immediately respond and provide a new address of the destination URI. The redirection rule is often the final rule.
RP (permanent redirect)
It is almost the same as the [R] flag, but the 301http status code is released instead of the 302http status code.
U (unmangle log)
Uri is recorded when the URI is a source requirement rather than a rewrite Requirement
O (normalize)
Standardize the string before implementation. Standardization includes URL-ENCODING, invalid character re-movement, etc. This tag is useful for URLs and URLS-ENDODED Headers
CL (case lower)
Lowercase
Cu (Case upper)
Uppercase
To re-move the header, the format string mode should generate an empty string. For example, this rule will re-remove the proxy information from the customer request.
Rewriteheader User-Agent:. * $0
And the rule adds the OLD-URL header to the request.
Rewritecond URL (. *) rewriteheader old-URL: ^ $1
The last example directs all WebDAV requests to/WebDAV by changing the request method. ASP
Rewritecond method options
Rewriterule (. *)/WebDAV. asp? $1
Rewriteheader method options get
Rewriteproxy Directive
Syntax: rewriteproxy pattern formatstring [flags]
Force the target URI to be a proxy internally and immediately scale up to cope with proxy requirements through ISAPI. This will allow IIS to act as a proxy server and re-route to other sites and servers
Pattern
Restrict rule expressions to match request-Uri,
Formatstring
Specify the formatstring of the new Uri.
[Flags]
Is a command separation list of the following flags
D (delegate security)
Proxy mode will try to log on to the remote server with the current fake user qualification,
C (use credentials)
Proxy mode will try to log on to the remote server with the qualification specified in the URL or basic Authorization header file, with this flag you can use http: // User: password@host.com/path/syntax as the URL
F (Follow redirects)
By default, isapi_rewrite tries to redirect the redirection command returned by the remote map server to the local server namespace. If the remote server returns the redirection point to another location on the server, isapi_rewrite will modify this important targeted command to point to the current server name, which will prevent users from seeing the real (internal) server name
Use the f flag to forcibly track the redirection commands returned by the remote server in the proxy mode. If you do not need to receive the redirection command from the remote server at all, there is a redirection restriction in WinHTTP settings to avoid remote redirection loops.
I (ignore case)
Forcibly match characters regardless of case
U (unmangle log)
Uri is recorded when the URI is a source requirement rather than a rewrite Requirement
O (normalize)
Standardize the string before implementation. Standardization includes URL-ENCODING, invalid character re-movement, etc. This tag is useful for URLs and URLS-ENDODED Headers
Cacheclockrate Directive
Syntax: cacheclockrate Interval
This command only appears in the global configuration content. If this command appears in the site-level content, it will be ignored and the error information will be written to the httpd. parse. Errors file.
Isapi_rewrite caches is configured each time when it is loaded for the first time. You can use this command to limit the inactive periods that a specific site clears from the cache, you can set this parameter large enough to force isapi_rewrite to never clear the cache. Remember that any configuration file changes will be updated immediately after the next request, ignoring this period.
Interval
Specifies the time (in seconds) when the specified configuration is cleared out of the cache. The default value is 3600 (1 hour)
Enableconfig and disableconfig directives
Syntax:
Enableconfig [siteid | "site name"]
Disableconfig [siteid | "site name"]
Activate or disable site-level configuration for the selected site or change the default configuration. The default site-level configuration is not activated. This command only appears in the global configuration content.
Siteid
Numeric metabase identifier of a site
Site name
Name of the site as it appears in the IIS Console
Use this command without parameters to change the default configuration to the enable/disable configuration process.
Example
In the following example, the configuration only applies to the site whose id = 1 (typically the default site) is my site.
Disableconfig
Enableconfig 1
Enableconfig "my site"
The following example shows how to activate the somesite configuration because it is used to split the settings and overload the default settings.
Enableconfig "Some site"
Disableconfig
Enablerewrite and disablerewrite directives
Syntax:
Enablerewrite [siteid | "site name"]
Disablerewrite [siteid | "site name"]
Activate or not activate rewrite for the selected site or change the default configuration. The default rewrite configuration is activated. This command only appears in the global configuration content.
Siteid
Numeric metabase identifier of a site
Site name
Name of the site as it appears in the IIS console.
If you do not use the parameter, this command will be activated or not activated.
Repeatlimit Directive
Syntax: repeatlimit limit
This command can appear in the global and site-level configuration files. If the command appears in the global configuration file, the global restrictions on all sites are changed, in the site-level configuration, only the restrictions on this site are changed, and the restriction cannot exceed the global limit.
Isapi_rewrite allows loops when implementing rules. This command allows you to limit the maximum number of possible loops. It can be set to 0 or 1, but does not support loops,
Limit
Maximum number of cycles. The default value is 32.
Rfstyle Directive
Syntax: rfstyle old | new
Configuration Utility
Isapi_rewrite full includes the configuration function (which can be started in the isapi_rewrite Program Group). It allows you to view the test status and enter the registration code (if not registered during installation ), in addition, some product functions related to Agent Mode operations are adjusted. Utility is an Attribute Table composed of three pages.
Trial page allows you to browse the tiral status and enter the registration code (if not registered during installation)
Settings page
This page contains the edit box for the following parameters
Helper URL
This parameter affects the contact information between the filter and the proxy module. It can be a file extension (such as. isrwhlp) with a dot prefix or an absolute path,
In the first case, the extension name is appended to the initial request URI and the agent module is activated through script map. The default extension isrwhlp is added to the global script map during the installation process, if you change the extension or your application does not inherit the global script map settings, You Should manually add the entry required for the script map. This should have the following parameters:
Executable: an absolute path to the rwhelper. dll in the short form
Extension: desired extension (. isrwhlp is default)
Verbs radio button: All verbs
Script Engine checkbox: checked
Check that file exists checkbox: unchecked
We have created a wsh script proxycfg. vbs which can be registered in a script maps. It is located in the installation folder and can be run in the following command line:
Cscript proxycfg. vbs [-R] [metabasepath]
Optional-r force-register Extension
Optional metabasepath parameter allows specification of the first metabase key to process. By default it is "/localhost/W3SVC ".
To register in all existing script maps, use the following command line to activate the script:
Cscript proxycfg. vbs-R
In the second case, you should provide a URI as the value of 'helper url'. You should also map an isapi_rewrite installation folder as the Virtual File home of the beautiful site.
Note: iis5 (which may include IIS4) has a problem with the long directory name based on the customer's response. We strongly recommend that you use the short directory name.
Worker threads limit
This parameter limits the number of worker threads in the proxy extension thread pool. The default value is 0, which means that the limit is equal to the number of processors multiplied by 2.
Active threads limit
This parameter limits the number of currently running threads. This quantity cannot be greater than "worker threads limit". The default value 0 indicates equal to the number of processors.
The queue size parameter defines the maximum number of requests. If you have seen the queue timeout expired "information, you can add this parameter to the Application Event Log.
Queue timeout
This parameter defines the maximum wait time for new requests to be prevented in the internal request queue. If you have seen the queue timeout expired "information, you can add this parameter in the Application Event Log.
Connect timeout
Set proxy module connection timeout in milliseconds
Send timeout
Set the sending timeout of the Agent module in milliseconds
Receive timeout
Set the sending timeout of the Agent module in milliseconds