📄 mod_rewrite.html.en
字号:
<div class="directive-section"><h2><a name="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the lock file used for <code class="directive"><a href="#rewritemap">RewriteMap</a></code>synchronization</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr><tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr><tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr><tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr></table> <p>This directive sets the filename for a synchronization lockfile which mod_rewrite needs to communicate with <code class="directive"><a href="#rewritemap">RewriteMap</a></code> <em>programs</em>. Set this lockfile to a local path (not on a NFS-mounted device) when you want to use a rewriting map-program. It is not required for other types of rewriting maps.</p></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engineprocessing</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr><tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr><tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr></table> <p>The <code class="directive">RewriteLog</code> directive sets the name of the file to which the server logs any rewriting actions it performs. If the name does not begin with a slash ('<code>/</code>') then it is assumed to be relative to the <em>Server Root</em>. The directive should occur only once per server config.</p><div class="note"> To disable the logging of rewriting actions it is not recommended to set <em>Filename</em> to <code>/dev/null</code>, because although the rewriting engine does not then output to a logfile it still creates the logfile output internally. <strong>This will slow down the server with no advantage to the administrator!</strong> To disable logging either remove or comment out the <code class="directive">RewriteLog</code> directive or use <code>RewriteLogLevel 0</code>!</div><div class="note"><h3>Security</h3>See the <a href="../misc/security_tips.html">Apache Security Tips</a>document for details on why your security could be compromised if thedirectory where logfiles are stored is writable by anyone other thanthe user that starts the server.</div><div class="example"><h3>Example</h3><p><code>RewriteLog "/usr/local/var/apache/logs/rewrite.log"</code></p></div></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewriteengine</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr><tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr><tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr></table> <p>The <code class="directive">RewriteLogLevel</code> directive sets the verbosity level of the rewriting logfile. The default level 0 means no logging, while 9 or more means that practically all actions are logged.</p> <p>To disable the logging of rewriting actions simply set <em>Level</em> to 0. This disables all rewrite action logs.</p><div class="note"> Using a high value for <em>Level</em> will slow down your Apache server dramatically! Use the rewriting logfile at a <em>Level</em> greater than 2 only for debugging!</div><div class="example"><h3>Example</h3><p><code>RewriteLogLevel 3</code></p></div></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em></code></td></tr><tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr><tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available inApache 2.0.41 and later</td></tr></table> <p>The <code class="directive">RewriteMap</code> directive defines a <em>Rewriting Map</em> which can be used inside rule substitution strings by the mapping-functions to insert/substitute fields through a key lookup. The source of this lookup can be of various types.</p> <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is the name of the map and will be used to specify a mapping-function for the substitution strings of a rewriting rule via one of the following constructs:</p> <p class="indent"> <strong><code>${</code> <em>MapName</em> <code>:</code> <em>LookupKey</em> <code>}</code><br /> <code>${</code> <em>MapName</em> <code>:</code> <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> <code>}</code></strong> </p> <p>When such a construct occurs the map <em>MapName</em> is consulted and the key <em>LookupKey</em> is looked-up. If the key is found, the map-function construct is substituted by <em>SubstValue</em>. If the key is not found then it is substituted by <em>DefaultValue</em> or by the empty string if no <em>DefaultValue</em> was specified.</p> <p>The following combinations for <em>MapType</em> and <em>MapSource</em> can be used:</p> <ul> <li> <strong>Standard Plain Text</strong><br /> MapType: <code>txt</code>, MapSource: Unix filesystem path to valid regular file <p>This is the standard rewriting map feature where the <em>MapSource</em> is a plain ASCII file containing either blank lines, comment lines (starting with a '#' character) or pairs like the following - one per line.</p> <p class="indent"> <strong><em>MatchingKey</em> <em>SubstValue</em></strong> </p><div class="example"><h3>Example</h3><pre>#### map.txt -- rewriting map##Ralf.S.Engelschall rse # Bastard Operator From HellMr.Joe.Average joe # Mr. Average</pre></div><div class="example"><p><code>RewriteMap real-to-user txt:/path/to/file/map.txt</code></p></div> </li> <li> <strong>Randomized Plain Text</strong><br /> MapType: <code>rnd</code>, MapSource: Unix filesystem path to valid regular file <p>This is identical to the Standard Plain Text variant above but with a special post-processing feature: After looking up a value it is parsed according to contained ``<code>|</code>'' characters which have the meaning of ``or''. In other words they indicate a set of alternatives from which the actual returned value is chosen randomly. Although this sounds crazy and useless, it was actually designed for load balancing in a reverse proxy situation where the looked up values are server names. Example:</p><div class="example"><pre>#### map.txt -- rewriting map##static www1|www2|www3|www4dynamic www5|www6</pre></div><div class="example"><p><code>RewriteMap servers rnd:/path/to/file/map.txt</code></p></div> </li> <li> <strong>Hash File</strong><br /> MapType: <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem path to valid regular file <p>Here the source is a binary format DBM file containing the same contents as a <em>Plain Text</em> format file, but in a special representation which is optimized for really fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or db depending on <a href="../install.html#dbm">compile-time settings</a>. If the <em>type</em> is ommitted, the compile-time default will be chosen. You can create such a file with any DBM tool or with the following Perl script. Be sure to adjust it to create the appropriate type of DBM. The example creates an NDBM file.</p><div class="example"><pre>#!/path/to/bin/perl#### txt2dbm -- convert txt map to dbm format##use NDBM_File;use Fcntl;($txtmap, $dbmmap) = @ARGV;open(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n";tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644) or die "Couldn't create $dbmmap!\n";while (<TXT>) { next if (/^\s*#/ or /^\s*$/); $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);}untie %DB;close(TXT);</pre></div><div class="example"><p><code>$ txt2dbm map.txt map.db</code></p></div> </li> <li> <strong>Internal Function</strong><br /> MapType: <code>int</code>, MapSource: Internal Apache function <p>Here the source is an internal Apache function. Currently you cannot create your own, but the following functions already exists:</p> <ul> <li><strong>toupper</strong>:<br /> Converts the looked up key to all upper case.</li> <li><strong>tolower</strong>:<br /> Converts the looked up key to all lower case.</li> <li><strong>escape</strong>:<br /> Translates special characters in the looked up key to hex-encodings.</li> <li><strong>unescape</strong>:<br /> Translates hex-encodings in the looked up key back to special characters.</li> </ul> </li> <li> <strong>External Rewriting Program</strong><br /> MapType: <code>prg</code>, MapSource: Unix filesystem path to valid regular file <p>Here the source is a program, not a map file. To create it you can use the language of your choice, but the result has to be a executable (<em>i.e.</em>, either object-code or a script with the magic cookie trick '<code>#!/path/to/interpreter</code>' as the first line).</p> <p>This program is started once at startup of the Apache servers and then communicates with the rewriting engine over its <code>stdin</code> and <code>stdout</code> file-handles. For each map-function lookup it will
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -