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

📄 mod_rewrite.html.en

📁 Apache2.2.4 with OpenSSL 0.9.8e 提供HTTP及HTTPS服务。 带QuickUsage
💻 EN
📖 第 1 页 / 共 5 页
字号:
<div class="note"><h3>Note:</h3>
              All of these tests can
              also be prefixed by an exclamation mark ('!') to
              negate their meaning.
</div>
        </li>

	<li>You can also set special flags for
      <em>CondPattern</em> by appending
        <strong><code>[</code><em>flags</em><code>]</code></strong>
      as the third argument to the <code>RewriteCond</code>
      directive, where <em>flags</em> is a comma-separated list of any of the
      following flags:

      <ul>
        <li>'<strong><code>nocase|NC</code></strong>'
        (<strong>n</strong>o <strong>c</strong>ase)<br />
        This makes the test case-insensitive - differences 
	between 'A-Z' and 'a-z' are ignored, both in the
        expanded <em>TestString</em> and the <em>CondPattern</em>.
        This flag is effective only for comparisons between
        <em>TestString</em> and <em>CondPattern</em>. It has no
        effect on filesystem and subrequest checks.</li>

        <li>
          '<strong><code>ornext|OR</code></strong>'
          (<strong>or</strong> next condition)<br />
          Use this to combine rule conditions with a local OR
          instead of the implicit AND. Typical example: 

<div class="example"><pre>
RewriteCond %{REMOTE_HOST}  ^host1.*  [OR]
RewriteCond %{REMOTE_HOST}  ^host2.*  [OR]
RewriteCond %{REMOTE_HOST}  ^host3.*
RewriteRule ...some special stuff for any of these hosts...
</pre></div>

          Without this flag you would have to write the condition/rule
          pair three times.
        </li>
      </ul>
      </li>
     </ol>

      <p><strong>Example:</strong></p>

       <p>To rewrite the Homepage of a site according to the
        ``<code>User-Agent:</code>'' header of the request, you can
        use the following: </p>

<div class="example"><pre>
RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
RewriteRule  ^/$                 /homepage.max.html  [L]

RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.*
RewriteRule  ^/$                 /homepage.min.html  [L]

RewriteRule  ^/$                 /homepage.std.html  [L]
</pre></div>

        <p>Explanation: If you use a browser which identifies itself 
	as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
        get the max homepage (which could include frames, or other special
	features).
        If you use the Lynx browser (which is terminal-based), then
	you get the min homepage (which could be a version designed for 
	easy, text-only browsing).
	If neither of these conditions apply (you use any other browser,
	or your browser identifies itself as something non-standard), you get
        the std (standard) homepage.</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="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</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">RewriteEngine</code> directive enables or
      disables the runtime rewriting engine. If it is set to
      <code>off</code> this module does no runtime processing at
      all. It does not even update the <code>SCRIPT_URx</code>
      environment variables.</p>

      <p>Use this directive to disable the module instead of
      commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>

      <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">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 engine
processing</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 how 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>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 rewrite
engine</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 in
Apache 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>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> 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 Hell
Mr.Joe.Average        joe   # Mr. Average

⌨️ 快捷键说明

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