⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_rewrite.html

📁 这个是我在web培训时老师提供的手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:

      <p>Note that, by default, rewrite configurations are not
      inherited. This means that you need to have a
      <code>RewriteEngine on</code> directive for each virtual host
      in which you wish to use it.</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="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#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">语法</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#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">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Sets the name of the file used for logging rewrite engine
processing</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_rewrite</td></tr>
</table>
      <p><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>安全</h3>

See the <a href="../misc/security_tips.html">Apache Security Tips</a>
document for details on why your security could be compromised if the
directory where logfiles are stored is writable by anyone other than
the user that starts the server.
</div>

<div class="example"><h3>示例</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">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Sets the verbosity of the log file used by the rewrite
engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>RewriteLogLevel 0</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_rewrite</td></tr>
</table>
      <p><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>示例</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">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Defines a mapping function for key-lookup</td></tr>
<tr><th><a href="directive-dict.html#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">作用域</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_rewrite</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">兼容性</a></th><td>The choice of different dbm types is available in
Apache 2.0.41 及以后的版本中可用</td></tr>
</table>
      <p><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><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>For example, you might define a
      <code class="directive">RewriteMap</code> as:</p>

      <div class="example"><p><code>
      RewriteMap examplemap txt:/path/to/file/map.txt
      </code></p></div>

      <p>You would then be able to use this map in a
      <code class="directive">RewriteRule</code> as follows:</p>

      <div class="example"><p><code>
      RewriteRule ^/ex/(.*) ${examplemap:$1}
      </code></p></div>

      <p>The following combinations for <em>MapType</em>和<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>示例</h3><pre>
##
##  map.txt -- rewriting map
##

Ralf.S.Engelschall    rse   # Bastard Operator From Hell
Mr.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. For example, you might use the following map
          file and directives to provide a random load balancing between
          several back-end server, via a reverse-proxy. Images are sent
          to one of the servers in the 'static' pool, while everything
          else is sent to one of the 'dynamic' pool.</p>
          <p>Example:</p>

<div class="example"><h3>Rewrite map file</h3><pre>
##
##  map.txt -- rewriting map
##

static   www1|www2|www3|www4
dynamic  www5|www6
</pre></div>

<div class="example"><h3>Configuration directives</h3><p><code>
RewriteMap servers rnd:/path/to/file/map.txt<br />
<br />
RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
[NC,P,L]<br />
RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
</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 omitted, 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, "&lt;$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 (&lt;TXT&gt;) {
  next if (/^\s*#/ or /^\s*$/);
  $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -