Apache. htaccess pseudo-static page
Static page address: http: // 211.166.45.10/company/new/new_assist.html
The specified dynamic address: php? Id = 10000 "> http: // 211.166.45.10/company/new. php? Id = 10000
Code in the dynamic file:
Style: <link href = "css/css.css" type = "text/css" rel = "stylesheet"/>
Figure:
Apache httpd. conf settings:
LoadModule rewrite_module libexec/apache22/mod_rewrite.so
Options FollowSymLinks
AllowOverride All
Alias "/company" "/usr/local/www/company/httpdocs /"
<Directory "/usr/local/www/company/httpdocs/">
Order Allow, Deny
Allow from all
</Directory>
. Htaccess settings:
Rewriteengine on
RewriteBase/company/
RewriteRule/new/new_(%0-9%1,%%}.html $ new. php? Id = $1
Previously, we used a real static page and included more than 20000 pages. Therefore, pseudo-static pages can only be accessed using http: // 211.166.45.10/company/new/new_assist.html, but new. php is in the root directory and a directory is different from the pseudo static address. How can I set the style and image to be opened normally?
The command scope is. htaccess RewriteEngine On | Off.
RewriteEngine enables or disables the rewrite function On or Off.
Rewrite invocations do not inherit, so you have to add this command to every virtual host that you want to use the rewrite function.
RewriteBase URL-path
The RewriteBase command explicitly sets the baseline URL for directory-level rewriting. In the following section, you can see that RewriteRule can be used in Directory-level configuration files (. htaccess) and take effect in a local range. That is, the rule actually handles only part of the local path prefix. After processing, the path will be automatically attached back. The default value is "RewriteBase physical-directory-path ".
When replacing a new URL, this module must inject the URL into the server again. Therefore, it must know the corresponding URL prefix or URL benchmark. Generally, this prefix is the corresponding file path. However, most website URLs do not directly correspond to their physical file paths, so this assumption is generally not acceptable! In this case, you must use the RewriteBase command to specify the correct URL prefix.
If the URL of your website server does not directly correspond to the path of the physical file, but you need to use the RewriteBase command, you must specify the RewriteRule in each corresponding. htaccess file.
RewriteCond TestString CondPattern
The RewriteCond command defines a condition for a rule, that is, one or more RewriteCond commands before a RewriteRule command. The rewrite rule after the condition takes effect only when the current URI matches pattern and meets these conditions.
Notice: All of these tests can also be prefixed by an exclamation mark ('! ') To negate their meaning. In a regular expression, ^ is used for reverse expression! Number reversed
RewriteOptions Options
Sets some special options for the rewrite engine.
Set some special options for rewrite.
The Option string can be currently only one: inherit
Inherit
This value forces the current configuration to inherit its parent configuration. In the VM-level configuration, it means that the ing tables, conditions, and rules of the master server can be inherited. In Directory-level configuration, it means that the conditions and rules in. htaccess of its parent directory can be inherited.
MaxRedirects = number
To avoid Directory-level RewriteRule endless internal redirection, mod_rewrite stops processing this request when the number of such redirection and 500 Internal Server errors reaches a maximum. If you really need to allow more than 10 Internal redirects for each request, you can increase this value.
This forces the current configuration to inherit the configuration of the parent.
Forces the current configuration to inherit its parent configuration.
In the per-virtual-server environment, maps, conditions, and rules will be inherited!
In the per-directory environment, it means that the condition in the. htaccess configuration of its parent directory will be inherited by rules!
RewriteRule Pattern Substitution [flags]
[Pre] Text :. any single Character [chars] Character class: One of chars [^ chars] Character class: None of chars text1 | select either text1 or text2Quantifiers: quantifiers? 0 or 1 of the front text * 0 or N of the front text (N> 0) + 1 or N of the front text (N> 1) Grouping: (text) Grouping of text you can use $ N to get the content in (): (a | B) | (c | d) $1 $2 $3 Anchors: ^ Start of line anchor $ End of line anchorEscaping: char escape that participates char (for instance to specify the chars ". [] () "etc .) note: None and & [/pre]
========================================================== ========================================================== ==========
Flags
'Redirect | R [= code] '(force redirect)
Substitution prefixed with http: // thishost [: thisport]/(make the new URL a URI) can forcibly execute an external redirection. If the code is not specified, an HTTP response code 302 (temporary movement) is generated ). To use other response codes in the range of-, you only need to specify this value here. In addition, you can also use one of the following Symbol names: temp (default), permanent, seeother. the canonicalized URL can be fed back to the client. For example, rewrite ''/~ '':''/U/'', or add a slash to/u/user. Note: When using this tag, make sure that the field to be replaced is a valid URL! Otherwise, it will point to an invalid location! Remember that this tag is only prefixed with http: // thishost [: thisport]/on the URL, and the rewrite operation will continue. In general, if you want to stop the rewrite operation and redirect immediately, you also need to use the 'L' flag.
'Forbidden | f' (force the URL to be a forbidden)
Force the current URL to be disabled. That is, an HTTP response code 403 (forbidden) is immediately reported ). With this tag, you can link several RewriteConds to block some URLs with conditions.
'Gone | g' (force the URL to be an obsolete gone)
Force the current URL to be obsolete, that is, immediately feedback an HTTP response code 410 (obsolete ). Use this tag to indicate that the page has been deprecated and does not exist.
'Proxy | P' (force proxy)
This flag forces the replacement component internally as a proxy request, and immediately transfers the process to the proxy module (that is, rewrite rule processing is interrupted immediately. You must ensure that the replacement string is valid (for example, a common URI starting with http: // hostname) and can be processed by the Apache Proxy module. Using this tag, you can map some remote components to the local server namespace, thus enhancing the ProxyPass command function. Note: To use this function, the proxy module must be compiled on the Apache server. If you are not sure, check whether mod_proxy.c exists in the output of ''httpd-L. If yes, mod_rewrite can use this function. If not, you must enable mod_proxy and re-compile the ''httpd ''program.
'Last | L' (last rule last)
Stop the rewrite operation immediately and no other rewrite rules will be applied. It corresponds to the last command in Perl or the break command in C language. This mark can prevent the URL that has been rewritten from being overwritten by its subsequent rules. For example, you can use it to rewrite the root path URL ('/') to an existing URL, for example, '/e/www /'.
'Next | n' (re-execute next round)
Re-execute the rewrite operation (starting from the first rule again). At this time, the URL processed again is not the original URL, but the URL processed by the last rewrite rule. It corresponds to the next command in Perl or the continue command in C language. This flag allows you to re-start the rewrite operation, that is, immediately return to the loop header. But be careful not to create an endless loop!
'Chain | C' (chained linked to the next rule)
This flag links the current rule with the next rule (which can be connected to its successor rule itself and can be so repeated. It produces the following effect: if a rule is matched, it will usually continue to process its successor rule, that is, this tag does not work; if the rule cannot be matched, the subsequent link rules are ignored. For example, when executing an external redirection, you may need to delete ''. www'' for a directory-level rule set (''. www'' should not appear here ).
'Type | T = MIME-type' (mandatory MIME type)
The MIME type of the target file must be MIME-type. For example, it can be used to simulate the ScriptAlias command in mod_alias. The MIME type of all files in the ing directory must be ''application/x-httpd-cgi ''.
'Nosubreq | NS' (used only to process no internal sub-request for internal sub-requests)
When the current request is an internal subrequest, This flag forces the rewrite engine to skip this rewrite rule. For example, when mod_include tries to search for a possible default directory file (index. xxx), Apache will generate a request internally. It is not necessarily useful for subrequests. If the entire rule set works, it may even cause errors. Therefore, you can use this tag to exclude certain rules. Follow the following principles as needed: If you use a URL prefix with CGI scripts to force them to be processed by CGI scripts, the error rate (or overhead) of sub-requests is high, in this case, you can use this tag.
'Nocase | NC '(case insensitive)
It makes Pattern case insensitive, that is, when Pattern matches the current URL, there is no difference between 'a-Z' and 'A-Z.
'Qsappend | qsa' (append request string append)
This flag forces the rewrite engine to append a request string to an existing replacement string, instead of simply replacing it. If you need to add information to the request string by using the rewrite rule, you can use this flag.
'Noescape | NEE' (no URI escaping is not escaped in the output)
This flag prevents mod_rewrite from applying regular URI escape rules to rewrite results. Generally, special characters (such as '%', '$', ';') are escaped as hexadecimal encoded values. This mark can prevent such escaping to allow symbols such as percent signs to appear in the output, such as: RewriteRule/foo/(. *)/bar? Arg = P1 % 3d $1 [R, NE]
Can '/foo/zed' be redirected to a secure request'/bar? Arg = P1 = zed '.
'Passthrough | pt' (pass through to the next processor)
This flag forces the rewrite engine to set the uri field in the internal structure request_rec to the value of the filename field. It is only a small modification so that it can be used for the Alias, ScriptAlias, redirect and other command output for subsequent processing. For example, if you want to use the mod_rewrite rewrite engine to rewrite/abc as/def and then use mod_alias to convert/def to/ghi, you can do this: rewriteRule ^/abc (. *)/def $1 [PT]
Alias/def/ghi
If the PT tag is omitted, although mod_rewrite works normally, that is, as an api uri to the file name translator, it can rewrite uri =/abc /... is filename =/def /..., however, subsequent mod_alias attempts to translate the URI to the file name will become invalid.
Note: If you need to mix different modules that contain URIs to the file name translator, you must use this tag. Mixed use of mod_alias and mod_rewrite is a typical example.
For Apache hackers
If there is a hook from the URI to the file name in Apache API besides the hook from the URI to the file name, you do not need to mark it! However, if there is no such hook, this tag is the only solution. Apache Group discussed this issue and added such a hook in Apache 2.0.
'Skip | S = num' (skip the subsequent rule skip)
This flag forces the rewrite engine to skip the num rules next to the current matching rule. It can construct a pseudo if-then-else: The last rule is the then clause, and the skipped skip = N rules are the else clause. (it is different from the 'chain | c' mark !)
'Env | E = VAR: VAL '(set the environment variable)
This flag sets the environment variable VAR value to VAL, which can contain extensible reverse referenced regular expressions $ N and % N. This tag can be used multiple times to set multiple variables. These variables can be indirectly referenced in many later cases, but usually in XSSI (via or CGI (for example, $ ENV {'var, you can also use % {ENV: VAR} as a reference in the pattern of the subsequent RewriteCond command. You can use it to strip from the URL and remember some information.
'Cookie | CO = NAME: VAL: domain [: lifetime [: path] '(set cookie)
It sets a cookie on the client browser. The cookie NAME is NAME and its value is VAL. The domain field is the cookie domain, such as '.apache.org'. The optional life time is the number of minutes in the cookie life cycle, and the optional path is the cookie path.