ISAPI-REWRITE pseudo static rule writing and description

  • 2020-05-06 12:04:36
  • OfStack

REWRITE pseudo-static

I. Apache configuration:
Go to /etc/httpd/conf/ and open the httpd.conf file.
Enable rewrite
# LoadModule rewrite_module modules/ mod_rewrite.so remove the preceding #
Enable.htaccess AllowOverride None changed to AllowOverride All
--------------------------------------------------------------------------------
Rewrite:
The server has configuration files that can't be changed by us, so most of the time we'll create a.htaccess file at the root of the site.
RewriteEngine on // start rewrite engine
RewriteRule ^ / index ([0-9] *) html $/ index php? id=$1 // "([0-9]*)" represents the scope with (.*) for all, same below.
RewriteRule ^ / index ([0-9] *) / $/ index php? id=$1 [R] // virtual directory
--------------------------------------------------------------------------------
mod_rewrite rule modifier
1) R forces external redirect
2) F disables URL and returns 403HTTP status code.
3) G forces URL to be GONE and returns 410HTTP status code.
4) P forces the use of proxy forwarding.
5) L indicates that the current rule is the last rule, and the rewriting of the rule after analysis is stopped.
6) N runs the rewrite process again from the first rule.
7) C is associated with the next rule. If the rule matches, it will be handled normally. The following modifier is invalid
8) T= MIME-type (force MIME type) mandatory MIME type
9) NS is only used for non-internal child requests
10) NC case insensitive
11) QSA append request string
12) NE does not escape the special character \%3d$1 is equivalent to =$1

ISAPI_Rewrite rule
The common ISAPI_Rewrite rule is
 
#  Exclude domain names that require normal access to the current virtual host ( web.3637.com www.3637.com )  
# RewriteCond Host: (?:web|www)\.eboat\.cn 
#  In most cases it is a system that currently provides secondary domain name service (e.g.  
RewriteCond Host: web\.eboat\.cn 
RewriteRule (.*) $1 [L] 
#  Resolve non-canonical directories (none at the end) / The problem of)  
#  But only if the directory name does not contain .' The file name must contain, otherwise you cannot distinguish between the two  
#  If the guarantee URL This rule is not required for the directory name specification in  
RewriteRule ^/([^.]+[^/]$) /$1/ [L,R] 
#  Extract any secondary domain name (that is, the first term)  
#  with [a-zA-Z0-9_-] Restrict the name character, overwrite Url to Home/ subdirectory  
#  Such as  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 domain names that require normal access to the current virtual host ( web.3637.com www.3637.com )  
# RewriteCond Host: (?:web|www)\.eboat\.cn 
#  In most cases it is a system that currently provides secondary domain name service (e.g.  
RewriteCond Host: web\.eboat\.cn 
RewriteRule (.*) $1 [L] 
#  Resolve non-canonical directories (none at the end) / The problem of)  
#  But only if the directory name does not contain .' The file name must contain, otherwise you cannot distinguish between the two  
#  If the guarantee URL This rule is not required for the directory name specification in  
RewriteRule ^/([^.]+[^/]$) /$1/ [L,R] 
#  Extract any secondary domain name (that is, the first term)  
#  with [a-zA-Z0-9_-] Restrict the name character, overwrite Url to Home/ subdirectory  
#  Such as  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 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 custom rules 
RewriteCond Host: (.+) 
RewriteCond  instruction  

Syntax :(syntax) RewriteCond TestVerb CondPattern [Flags]
This directive defines a conditional rule that preempts the RewriteCond directive before the RewriteRule or RewriteHeader or RewriteProxy directives, and the subsequent rule is applied only if its pattern matches the current state of URI and additional conditions are applied.

TestVerb

Specifies verb that will be matched against regular expression.
The specially defined verb matches the specified expression
TestVerb=(URL | METHOD | VERSION | HTTPHeaderName: | %ServerVariable) where:

URL - returns Request-URI of client request as described in RFC 2068 (HTTP 1.1);
Returns Request-URI
for the requirements described by the client in RFC2068 METHOD - returns HTTP method of client request (OPTIONS, GET, HEAD, POST, PUT, DELETE or TRACE);
Returns the HTTP method
for the client requirements (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 should include the trailing colon ":". If specified header does not exists in a client's request TestVerb is treated as empty string.
Returns the value
for the HTTP header file with a specific meaning 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 refer to RFC2068


ServerVariable returns the value of a server variable with a specific meaning. For example, for the server port, the list of all server variables should be established in the IIS document, and the variable name should be predetermined by the % character.
CondPattern
The regular expression to match TestVerb
The regular expression matches TestVerb
[Flags]
Flags is a comma-separated list of the following flags:


O (nOrmalize)
Normalizes string before processing. Normalization includes removing of an URL-encoding, illegal characters, etc. This flag is useful with URLs and URL-encoded headers
RewriteRule instruction
Syntax: RewriteRule Pattern FormatString [Flags]
This directive can occur more than once, and each directive defines a separate rewrite rule. The definition of these rules is important because the rule is useful

when the application runs

I (ignore case)
To force a character match regardless of case, this FLAG affects the RewriteRule directive and the corresponding RewriteCond directive
F (Forbidden)
Reacting to the client, stop the REWRITING process and send a 403 error, note that FORMATSTRING is useless in this case and can be set to any non-empty string.
L (last rule)
Instead of applying any rewrite rule to stop the rewrite process here, use this FLAG to prevent the currently overridden URI from being overridden by a later rule to overwrite
again N (Next iteration)
Force REWRITINGENGINE to adjust the rule target and restart the rule check from scratch (all changes will be saved). The number of restarts is limited by the value specified by RepeatLimit. If this value exceeds N FLAG,
will be ignored NS (Next iteration of the same rule)
Work with the N flag does not restart the rule rule process from the same rule (for example, to force a repeat rule application). Specify a maximum number of rules to be repeated by the RepeatLimit directive,
P (force proxy)
Mandatory purpose URI internally enforces the proxy requirement and immediately responds to the proxy requirement through the ISAPI extension. You must confirm that the proxy string is a valid URI including the protocol host, etc. Otherwise the proxy will return an error
R (explicit redirect)
Forces the server to issue an immediate reply to the client with the new address of the destination URI. The redirect rule is often the last rule
RP (permanent redirect)
It is almost identical to the [R] tag but publishes the 301HTTP status instead of the 302HTTP status code
U (Unmangle Log)
Note URI
when URI is the source requirement and not the rewrite requirement O (nOrmalize)
Standardize the string before doing it. Standardization includes URL-ENCODING, re-movement of illegal characters, etc. This tag is useful for
for URLS and URLS-ENDODED headers CL (Case Lower)
Lowercase
CU (Case Upper)
Capital
RewriteHeader directive
Syntax: RewriteHeader HeaderName Pattern FormatString [Flags]
This directive, a more general variant of RewriteRule, overrides not only the client requirements section of URL, but also the HTTP header, which is not only used for overrides. Generate, remove any HTTP headers, and even change the client request method
HeaderName
Specifies the customer header to be overridden with the same value as the TestVerb parameter in the RewriteCond directive

Pattern
Qualify regular expressions to match Request-URI,
FormatString
The qualification will generate a new FormatString
for URI [Flags]
Is a command delimited list
with the following FLAGS I (ignore case)
To force a character match regardless of case, this FLAG affects the RewriteRule directive and the corresponding RewriteCond directive
F (Forbidden)
Reacting to the client, stop the REWRITING process and send a 403 error, note that FORMATSTRING is useless in this case and can be set to any non-empty string.
L (last rule)
Instead of applying any rewrite rule to stop the rewrite process here, use this FLAG to prevent the currently overridden URI from being overridden by a later rule to overwrite
again N (Next iteration)
Force REWRITINGENGINE to adjust the rule target and restart the rule check from scratch (all changes will be saved). The number of restarts is limited by the value specified by RepeatLimit. If this value exceeds N FLAG,

will be ignored

NS (Next iteration of the same rule)
Work with the N flag does not restart the rule rule process from the same rule (for example, to force a repeat rule application). Specify a maximum number of rules to be repeated by the RepeatLimit directive,

R (explicit redirect)
Forces the server to issue an immediate reply to the client with the new address of the destination URI. The redirect rule is often the last rule
RP (permanent redirect)
It is almost identical to the [R] tag but publishes 301HTTP status instead of 302HTTP status code
U (Unmangle Log)
Note URI
when URI is the source requirement and not the override requirement O (nOrmalize)
Standardize the string before doing it. Standardization includes URL-ENCODING, re-movement of illegal characters, etc. This flag is useful for URLS and URLS-ENDODED headers
CL (Case Lower)
Lowercase
CU (Case Upper)
Capital

To remove the header, the FORMAT STRING pattern should generate an empty string, for example this rule will remove the proxy

from the customer request

Related articles: