Writing and description of pseudo-static ISAPI-REWRITE rules

Source: Internet
Author: User

REWRITE pseudo-static

1. Apache configuration:
Go to the/etc/httpd/conf/directory and open the httpd. conf file.
Enable rewrite
# LoadModule rewrite_module modules/mod_rewrite.so remove the previous #
Enable. htaccess AllowOverride None to: AllowOverride All
--------------------------------------------------------------------------------
Ii. Rewrite writing
We cannot modify the configuration file on the server. In most cases, we need to create a. htaccess file under the root directory of the website.
RewriteEngine on // start the rewrite Engine
RewriteRule ^/index ([0-9] * pai.html $/index. php? Id = $1 // "([0-9] *)" indicates that the range (. *) indicates all, the same below.
RewriteRule ^/index ([0-9] *)/$/index. php? Id = $1 [R] // virtual directory
--------------------------------------------------------------------------------
3. mod_rewrite rule Modifier
1) R forces external redirection
2) F disables the URL and returns the 403HTTP status code.
3) If G forces the URL to be GONE, the response HTTP status code is returned.
4) P enforces proxy forwarding.
5) L indicates that the current rule is the last rule, and the rule is overwritten after analysis is stopped.
6) N re-run the rewrite process from the first rule.
7) C. associate with the next rule. If the rule matches, it will be processed normally. The following modifier is invalid.
8) T = MIME-type (force MIME type) force MIME type
9) NS is only used for non-Internal subrequests
10) the NC is case insensitive.
11) QSA append request string
12) NE does not output escape special characters \ % 3d $1 is equivalent to = $1

Description of ISAPI_Rewrite rules
Common ISAPI_Rewrite rulesCopy codeThe Code is as follows: # exclude the domain name that the current VM needs to access (web.3637.com www.3637.com)
# RewriteCond Host :(? : Web | www) \. eboat \. cn
# In most cases, it is a system that currently provides second-level domain name services (such as a website creation system)
RewriteCond Host: web \. eboat \. cn
RewriteRule (. *) $1 [L]
# Solve the problem of nonstandard directories (no at the end)
# But the premise is that the directory name does not include '.' And the file name must contain; otherwise, the two cannot be distinguished.
# This rule is not required if the directory name in the URL is specified
RewriteRule ^/([^.] + [^/] $)/$1/[L, R]
# Extract any second-level domain name (that is, the first word)
# Use [a-zA-Z0-9 _-] to limit the name character, rewrite the Url to the Home/subdirectory
# For example, test.3637.com => web.3637.com/Home/test
RewriteCond Host: ([a-zA-Z0-9 _-] +) \. eboat \. cn
RewriteRule ^/(. *)/Home/$1/$2 [I, L]
[ISAPI_Rewrite]
RepeatLimit 1
# Defend your computer from some worm attacks
RewriteRule .*(? : Global. asa | default \. ida | root \. exe | \. \.). *. [F, I, O]
# Exclude the domain name that the current VM needs to access (web.3637.com www.3637.com)
# RewriteCond Host :(? : Web | www) \. eboat \. cn
# In most cases, it is a system that currently provides second-level domain name services (such as a website creation system)
RewriteCond Host: web \. eboat \. cn
RewriteRule (. *) $1 [L]
# Solve the problem of nonstandard directories (no at the end)
# But the premise is that the directory name does not include '.' And the file name must contain; otherwise, the two cannot be distinguished.
# This rule is not required if the directory name in the URL is specified
RewriteRule ^/([^.] + [^/] $)/$1/[L, R]
# Extract any second-level domain name (that is, the first word)
# Use [a-zA-Z0-9 _-] to limit the name character, rewrite the Url to the Home/subdirectory
# For example, test.3637.com => web.3637.com/Home/test
RewriteCond Host: ([a-zA-Z0-9 _-] +) \. eboat \. cn
RewriteRule ^/(. *)/Home/$1/$2 [I, L]

HTTPD. ini file exampleCopy codeThe Code is as follows: [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 remove the Proxy from the client request

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.