github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_2_34/manual/mod/mod_rewrite.html.en (about)

     1  <?xml version="1.0" encoding="ISO-8859-1"?>
     2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     3  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
     4  <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
     5  <!--
     6          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     7                This file is generated from xml source: DO NOT EDIT
     8          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     9        -->
    10  <title>mod_rewrite - Apache HTTP Server Version 2.2</title>
    11  <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
    12  <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
    13  <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
    14  <script src="../style/scripts/prettify.min.js" type="text/javascript">
    15  </script>
    16  
    17  <link href="../images/favicon.ico" rel="shortcut icon" /><link href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html" rel="canonical" /></head>
    18  <body>
    19  <div id="page-header">
    20  <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
    21  <p class="apache">Apache HTTP Server Version 2.2</p>
    22  <img alt="" src="../images/feather.gif" /></div>
    23  <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
    24  <div id="path">
    25  <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.2</a> &gt; <a href="./">Modules</a></div>
    26  <div id="page-content">
    27  <div class="retired"><h4>Please note</h4>
    28              <p> This document refers to a legacy release (<strong>2.2</strong>) of Apache httpd. The active release (<strong>2.4</strong>) is documented <a href="http://httpd.apache.org/docs/current">here</a>. If you have not already upgraded, please follow <a href="http://httpd.apache.org/docs/current/upgrading.html">this link</a> for more information.</p>
    29          <p>You may follow <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html">this link</a> to go to the current version of this document.</p></div><div id="preamble"><h1>Apache Module mod_rewrite</h1>
    30  <div class="toplang">
    31  <p><span>Available Languages: </span><a href="../en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
    32  <a href="../fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
    33  </div>
    34  <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
    35  URLs on the fly</td></tr>
    36  <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
    37  <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>rewrite_module</td></tr>
    38  <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_rewrite.c</td></tr>
    39  <tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 1.3 and later</td></tr></table>
    40  <h3>Summary</h3>
    41  
    42        <p>This module uses a rule-based rewriting engine (based on a
    43        regular-expression parser) to rewrite requested URLs on the
    44        fly. It supports an unlimited number of rules and an
    45        unlimited number of attached rule conditions for each rule, to
    46        provide a really flexible and powerful URL manipulation
    47        mechanism. The URL manipulations can depend on various tests,
    48        of server variables, environment variables, HTTP
    49        headers, or time stamps. Even external database lookups in
    50        various formats can be used to achieve highly granular URL
    51        matching.</p>
    52  
    53        <p>This module operates on the full URLs (including the
    54        path-info part) both in per-server context
    55        (<code>httpd.conf</code>) and per-directory context
    56        (<code>.htaccess</code>) and can generate query-string
    57        parts on result. The rewritten result can lead to internal
    58        sub-processing, external request redirection or even to an
    59        internal proxy throughput.</p>
    60  
    61        <p>Further details, discussion, and examples, are provided in the
    62        <a href="../rewrite/">detailed mod_rewrite documentation</a>.</p>
    63  </div>
    64  <div id="quickview"><h3>Topics</h3>
    65  <ul id="topics">
    66  <li><img alt="" src="../images/down.gif" /> <a href="#quoting">Quoting Special Characters</a></li>
    67  <li><img alt="" src="../images/down.gif" /> <a href="#EnvVar">Environment Variables</a></li>
    68  <li><img alt="" src="../images/down.gif" /> <a href="#vhosts">Rewriting in Virtual Hosts</a></li>
    69  <li><img alt="" src="../images/down.gif" /> <a href="#Solutions">Practical Solutions</a></li>
    70  </ul><h3 class="directives">Directives</h3>
    71  <ul id="toc">
    72  <li><img alt="" src="../images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
    73  <li><img alt="" src="../images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
    74  <li><img alt="" src="../images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
    75  <li><img alt="" src="../images/down.gif" /> <a href="#rewritelock">RewriteLock</a></li>
    76  <li><img alt="" src="../images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
    77  <li><img alt="" src="../images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
    78  <li><img alt="" src="../images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
    79  <li><img alt="" src="../images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
    80  <li><img alt="" src="../images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
    81  </ul>
    82  <h3>See also</h3>
    83  <ul class="seealso">
    84  <li><a href="#rewriteflags">Rewrite Flags</a></li>
    85  </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
    86  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
    87  <div class="section">
    88  <h2><a name="quoting" id="quoting">Quoting Special Characters</a></h2>
    89  
    90        <p>As of Apache 1.3.20, special characters in
    91        <em>TestString</em> and <em>Substitution</em> strings can be
    92        escaped (that is, treated as normal characters without their
    93        usual special meaning) by prefixing them with a backslash ('\')
    94        character. In other words, you can include an actual
    95        dollar-sign character in a <em>Substitution</em> string by
    96        using '<code>\$</code>'; this keeps mod_rewrite from trying
    97        to treat it as a backreference.</p>
    98  </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
    99  <div class="section">
   100  <h2><a name="EnvVar" id="EnvVar">Environment Variables</a></h2>
   101  
   102        <p>This module keeps track of two additional (non-standard)
   103        CGI/SSI environment variables named <code>SCRIPT_URL</code>
   104        and <code>SCRIPT_URI</code>. These contain the
   105        <em>logical</em> Web-view to the current resource, while the
   106        standard CGI/SSI variables <code>SCRIPT_NAME</code> and
   107        <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
   108        System-view. </p>
   109  
   110        <p>Notice: These variables hold the URI/URL <em>as they were
   111        initially requested</em>, that is, <em>before</em> any
   112        rewriting. This is important to note because the rewriting process is
   113        primarily used to rewrite logical URLs to physical
   114        pathnames.</p>
   115  
   116  <div class="example"><h3>Example</h3><pre>SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
   117  SCRIPT_FILENAME=/u/rse/.www/index.html
   118  SCRIPT_URL=/u/rse/
   119  SCRIPT_URI=http://en1.engelschall.com/u/rse/</pre></div>
   120  
   121  </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   122  <div class="section">
   123  <h2><a name="vhosts" id="vhosts">Rewriting in Virtual Hosts</a></h2>
   124  
   125       <p>By default, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> configuration
   126       settings from the main server context are not inherited by
   127       virtual hosts. To make the main server settings apply to virtual
   128       hosts, you must place the following directives in each <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> section:</p>
   129  
   130       <div class="example"><p><code>
   131       RewriteEngine On<br />
   132       RewriteOptions Inherit
   133       </code></p></div>
   134  </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   135  <div class="section">
   136  <h2><a name="Solutions" id="Solutions">Practical Solutions</a></h2>
   137  
   138      <p>For numerous examples of common, and not-so-common, uses for
   139      mod_rewrite, see the <a href="../rewrite/">extended rewrite
   140      documentation.</a></p>
   141  
   142  </div>
   143  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   144  <div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
   145  <table class="directive">
   146  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
   147  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
   148  <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
   149  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
   150  <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
   151  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   152  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   153  </table>
   154        <p>The <code class="directive">RewriteBase</code> directive specifies the
   155        URL prefix to be used for per-directory (htaccess) 
   156        <code class="directive">RewriteRule</code> directives that substitute a relative
   157        path.</p>
   158        <p> This directive is <em>required</em> when you use a relative path
   159        in a substitution in per-directory (htaccess) context unless either
   160        of the following conditions are true:</p>
   161        <ul>
   162            <li> The original request, and the substitution, are underneath the 
   163                 <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
   164                 (as opposed to reachable by other means, such as 
   165                 <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>).</li>
   166            <li> The <em>filesystem</em> path to the directory containing the
   167                 <code class="directive">RewriteRule</code>, suffixed by the relative 
   168                 substitution is also valid as a URL path on the server 
   169                 (this is rare).</li>
   170        </ul>
   171  
   172  <p> In the example below, <code class="directive">RewriteBase</code> is necessary
   173      to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
   174      since the resource was not relative to the document root.  This 
   175      misconfiguration would normally cause the server to look for an "opt"
   176      directory under the document root.</p>
   177  <div class="example"><pre>DocumentRoot /var/www/example.com
   178  Alias /myapp /opt/myapp-1.2.3
   179  &lt;Directory /opt/myapp-1.2.3&gt;
   180  RewriteEngine On
   181  RewriteBase /myapp/
   182  RewriteRule ^index\.html$  welcome.html 
   183  &lt;/Directory&gt;</pre></div>
   184  
   185  </div>
   186  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   187  <div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
   188  <table class="directive">
   189  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
   190  </td></tr>
   191  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
   192        <em>TestString</em> <em>CondPattern</em></code></td></tr>
   193  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
   194  <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
   195  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   196  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   197  </table>
   198        <p>The <code class="directive">RewriteCond</code> directive defines a
   199        rule condition. One or more <code class="directive">RewriteCond</code>
   200        can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code> 
   201        directive. The following rule is then only used if both
   202        the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
   203  
   204        <p><em>TestString</em> is a string which can contain the
   205        following expanded constructs in addition to plain text:</p>
   206  
   207        <ul>
   208          <li>
   209            <strong>RewriteRule backreferences</strong>: These are
   210            backreferences of the form <strong><code>$N</code></strong>
   211            (0 &lt;= N &lt;= 9), which provide access to the grouped
   212            parts (in parentheses) of the pattern, from the
   213            <code>RewriteRule</code> which is subject to the current 
   214  	  set of <code>RewriteCond</code> conditions..
   215          </li>
   216          <li>
   217            <strong>RewriteCond backreferences</strong>: These are
   218            backreferences of the form <strong><code>%N</code></strong>
   219            (1 &lt;= N &lt;= 9), which provide access to the grouped
   220            parts (again, in parentheses) of the pattern, from the last matched
   221            <code>RewriteCond</code> in the current set
   222            of conditions.
   223          </li>
   224          <li>
   225            <strong>RewriteMap expansions</strong>: These are
   226            expansions of the form <strong><code>${mapname:key|default}</code></strong>.
   227            See <a href="#mapfunc">the documentation for
   228            RewriteMap</a> for more details.
   229          </li>
   230          <li>
   231            <strong>Server-Variables</strong>: These are variables of
   232            the form 
   233              <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
   234              <code>}</code></strong>
   235            where <em>NAME_OF_VARIABLE</em> can be a string taken
   236            from the following list: 
   237  
   238            <table>
   239            
   240              <tr>
   241                <th>HTTP headers:</th> <th>connection &amp; request:</th> <th />
   242  	    </tr>
   243  
   244              <tr>
   245  	      <td>
   246  		 HTTP_USER_AGENT<br />
   247                   HTTP_REFERER<br />
   248                   HTTP_COOKIE<br />
   249                   HTTP_FORWARDED<br />
   250                   HTTP_HOST<br />
   251                   HTTP_PROXY_CONNECTION<br />
   252                   HTTP_ACCEPT<br />
   253                </td>
   254  
   255                <td>
   256                   REMOTE_ADDR<br />
   257                   REMOTE_HOST<br />
   258                   REMOTE_PORT<br />
   259                   REMOTE_USER<br />
   260                   REMOTE_IDENT<br />
   261                   REQUEST_METHOD<br />
   262                   SCRIPT_FILENAME<br />
   263                   PATH_INFO<br />
   264                   QUERY_STRING<br />
   265                   AUTH_TYPE<br />
   266                </td>
   267  	      
   268  	      <td />
   269              </tr>
   270  
   271              <tr>
   272                <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
   273  	    </tr>
   274  
   275              <tr>
   276  	      <td>
   277  	         DOCUMENT_ROOT<br />
   278                   SERVER_ADMIN<br />
   279                   SERVER_NAME<br />
   280                   SERVER_ADDR<br />
   281                   SERVER_PORT<br />
   282                   SERVER_PROTOCOL<br />
   283                   SERVER_SOFTWARE<br />
   284                </td>
   285  
   286                <td>
   287                   TIME_YEAR<br />
   288                   TIME_MON<br />
   289                   TIME_DAY<br />
   290                   TIME_HOUR<br />
   291                   TIME_MIN<br />
   292                   TIME_SEC<br />
   293                   TIME_WDAY<br />
   294                   TIME<br />
   295                </td>
   296  
   297                <td>
   298                   API_VERSION<br />
   299                   THE_REQUEST<br />
   300                   REQUEST_URI<br />
   301                   REQUEST_FILENAME<br />
   302                   IS_SUBREQ<br />
   303                   HTTPS<br />
   304                </td>
   305              </tr>
   306            </table>
   307  
   308                  <p>These variables all
   309                  correspond to the similarly named HTTP
   310                  MIME-headers, C variables of the Apache server or
   311                  <code>struct tm</code> fields of the Unix system.
   312                  Most are documented elsewhere in the Manual or in
   313                  the CGI specification.</p>
   314  
   315                  <p>SERVER_NAME and SERVER_PORT depend on the values of 
   316                  <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> and
   317                  <code class="directive"><a href="../mod/core.html#usecanonicalphysicalport">UseCanonicalPhysicalPort</a></code>
   318                  respectively.</p>
   319  
   320                  <p>Those that are special to mod_rewrite include those below.</p>
   321  	<div class="note">
   322                  <dl>
   323                    <dt><code>IS_SUBREQ</code></dt>
   324  
   325                    <dd>Will contain the text "true" if the request
   326                    currently being processed is a sub-request,
   327                    "false" otherwise. Sub-requests may be generated
   328                    by modules that need to resolve additional files
   329                    or URIs in order to complete their tasks.</dd>
   330  
   331                    <dt><code>API_VERSION</code></dt>
   332  
   333                    <dd>This is the version of the Apache module API
   334                    (the internal interface between server and
   335                    module) in the current httpd build, as defined in
   336                    include/ap_mmn.h. The module API version
   337                    corresponds to the version of Apache in use (in
   338                    the release version of Apache 1.3.14, for
   339                    instance, it is 19990320:10), but is mainly of
   340                    interest to module authors.</dd>
   341  
   342                    <dt><code>THE_REQUEST</code></dt>
   343  
   344                    <dd>The full HTTP request line sent by the
   345                    browser to the server (e.g., "<code>GET
   346                    /index.html HTTP/1.1</code>"). This does not
   347                    include any additional headers sent by the
   348                    browser.  This value has not been unescaped 
   349                    (decoded), unlike most other variables below.</dd>
   350  
   351                    <dt><code>REQUEST_URI</code></dt>
   352  
   353                    <dd>The path component of the requested URI,
   354                    such as "/index.html".  This notably excludes the
   355                    query string which is available as as its own variable
   356                    named <code>QUERY_STRING</code>.</dd>
   357  
   358                    <dt><code>REQUEST_FILENAME</code></dt>
   359  
   360                    <dd>The full local filesystem path to the file or
   361                    script matching the request, if this has already
   362                    been determined by the server at the time 
   363                    <code>REQUEST_FILENAME</code> is referenced. Otherwise, 
   364                    such as when used in virtual host context, the same 
   365                    value as <code>REQUEST_URI</code>.</dd>
   366  
   367                    <dt><code>HTTPS</code></dt>
   368  
   369                    <dd>Will contain the text "on" if the connection is
   370                    using SSL/TLS, or "off" otherwise.  (This variable
   371                    can be safely used regardless of whether or not
   372                    <code class="module"><a href="../mod/mod_ssl.html">mod_ssl</a></code> is loaded).</dd>
   373  
   374                  </dl>
   375  </div>
   376          </li>
   377        </ul>
   378  
   379        <p>Other things you should be aware of:</p>
   380  
   381        <ol>
   382          <li><p>The variables SCRIPT_FILENAME and REQUEST_FILENAME
   383          contain the same value - the value of the
   384          <code>filename</code> field of the internal
   385          <code>request_rec</code> structure of the Apache server.
   386          The first name is the commonly known CGI variable name
   387          while the second is the appropriate counterpart of
   388          REQUEST_URI (which contains the value of the
   389          <code>uri</code> field of <code>request_rec</code>).</p>
   390          <p>If a substitution occurred and the rewriting continues,
   391          the value of both variables will be updated accordingly.</p>
   392          <p>If used in per-server context (<em>i.e.</em>, before the
   393          request is mapped to the filesystem) SCRIPT_FILENAME and
   394          REQUEST_FILENAME cannot contain the full local filesystem
   395          path since the path is unknown at this stage of processing.
   396          Both variables will initially contain the value of REQUEST_URI
   397          in that case. In order to obtain the full local filesystem
   398          path of the request in per-server context, use an URL-based
   399          look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
   400          the final value of REQUEST_FILENAME.</p></li>
   401  
   402          <li>
   403          <code>%{ENV:variable}</code>, where <em>variable</em> can be
   404  	any environment variable, is also available. 
   405  	This is looked-up via internal
   406          Apache structures and (if not found there) via
   407          <code>getenv()</code> from the Apache server process.</li>
   408  
   409          <li>
   410          <code>%{SSL:variable}</code>, where <em>variable</em> is the
   411          name of an <a href="mod_ssl.html#envvars">SSL environment
   412          variable</a>, can be used whether or not
   413          <code class="module"><a href="../mod/mod_ssl.html">mod_ssl</a></code> is loaded, but will always expand to
   414          the empty string if it is not.  Example:
   415          <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
   416          <code>128</code>. These variables are available even without
   417          setting the <code>StdEnvVars</code> option of the
   418          <code class="directive"><a href="../mod/mod_ssl.html#ssloptions">SSLOptions</a></code> directive.</li>
   419  
   420          <li>
   421          <code>%{HTTP:header}</code>, where <em>header</em> can be
   422  	any HTTP MIME-header name, can always be used to obtain the
   423  	value of a header sent in the HTTP request.
   424          Example: <code>%{HTTP:Proxy-Connection}</code> is
   425          the value of the HTTP header
   426          ``<code>Proxy-Connection:</code>''.
   427          <p>If a HTTP header is used in a condition this header is added to
   428          the Vary header of the response in case the condition evaluates
   429          to true for the request. It is <strong>not</strong> added if the
   430          condition evaluates to false for the request. Adding the HTTP header
   431          to the Vary header of the response is needed for proper caching.</p>
   432          <p>It has to be kept in mind that conditions follow a short circuit
   433          logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
   434          so that certain conditions might not be evaluated at all.</p></li>
   435  
   436          <li>
   437          <code>%{LA-U:variable}</code> can be used for look-aheads which perform
   438          an internal (URL-based) sub-request to determine the final
   439  	value of <em>variable</em>. This can be used to access
   440          variable for rewriting which is not available at the current 
   441  	stage, but will be set in a later phase.
   442  	<p>For instance, to rewrite according to the
   443          <code>REMOTE_USER</code> variable from within the
   444          per-server context (<code>httpd.conf</code> file) you must
   445          use <code>%{LA-U:REMOTE_USER}</code> - this
   446          variable is set by the authorization phases, which come
   447  	<em>after</em> the URL translation phase (during which mod_rewrite
   448  	operates).</p>
   449  	<p>On the other hand, because mod_rewrite implements
   450          its per-directory context (<code>.htaccess</code> file) via
   451          the Fixup phase of the API and because the authorization
   452          phases come <em>before</em> this phase, you just can use
   453  	<code>%{REMOTE_USER}</code> in that context.</p></li>
   454  
   455          <li>
   456          <code>%{LA-F:variable}</code> can be used to perform an internal
   457          (filename-based) sub-request, to determine the final value
   458          of <em>variable</em>. Most of the time, this is the same as
   459          LA-U above.</li>
   460        </ol>
   461  
   462        <p><em>CondPattern</em> is the condition pattern,
   463         a regular expression which is applied to the
   464        current instance of the <em>TestString</em>.
   465        <em>TestString</em> is first evaluated, before being matched against
   466        <em>CondPattern</em>.</p>
   467  
   468        <p><strong>Remember:</strong> <em>CondPattern</em> is a
   469        <em>perl compatible regular expression</em> with some
   470        additions:</p>
   471  
   472        <ol>
   473          <li>You can prefix the pattern string with a
   474          '<code>!</code>' character (exclamation mark) to specify a
   475          <strong>non</strong>-matching pattern.</li>
   476  
   477          <li>
   478            There are some special variants of <em>CondPatterns</em>.
   479            Instead of real regular expression strings you can also
   480            use one of the following: 
   481  
   482            <ul>
   483              <li>'<strong>&lt;CondPattern</strong>' (lexicographically 
   484  	    precedes)<br />
   485              Treats the <em>CondPattern</em> as a plain string and
   486              compares it lexicographically to <em>TestString</em>. True if
   487              <em>TestString</em> lexicographically precedes
   488              <em>CondPattern</em>.</li>
   489  
   490              <li>'<strong>&gt;CondPattern</strong>' (lexicographically
   491              follows)<br />
   492              Treats the <em>CondPattern</em> as a plain string and
   493              compares it lexicographically to <em>TestString</em>. True if
   494              <em>TestString</em> lexicographically follows
   495              <em>CondPattern</em>.</li>
   496  
   497              <li>'<strong>=CondPattern</strong>' (lexicographically
   498              equal)<br />
   499              Treats the <em>CondPattern</em> as a plain string and
   500              compares it lexicographically to <em>TestString</em>. True if
   501              <em>TestString</em> is lexicographically equal to
   502              <em>CondPattern</em> (the two strings are exactly
   503              equal, character for character). If <em>CondPattern</em>
   504              is <code>""</code> (two quotation marks) this
   505              compares <em>TestString</em> to the empty string.</li>
   506  
   507              <li>'<strong>-d</strong>' (is
   508              <strong>d</strong>irectory)<br />
   509               Treats the <em>TestString</em> as a pathname and tests
   510              whether or not it exists, and is a directory.</li>
   511  
   512              <li>'<strong>-f</strong>' (is regular
   513              <strong>f</strong>ile)<br />
   514               Treats the <em>TestString</em> as a pathname and tests
   515              whether or not it exists, and is a regular file.</li>
   516  
   517              <li>'<strong>-s</strong>' (is regular file, with
   518              <strong>s</strong>ize)<br />
   519              Treats the <em>TestString</em> as a pathname and tests
   520              whether or not it exists, and is a regular file with size greater
   521              than zero.</li>
   522  
   523              <li>'<strong>-l</strong>' (is symbolic
   524              <strong>l</strong>ink)<br />
   525              Treats the <em>TestString</em> as a pathname and tests
   526              whether or not it exists, and is a symbolic link.</li>
   527  
   528              <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
   529              permissions)<br />
   530              Treats the <em>TestString</em> as a pathname and tests
   531  	    whether or not it exists, and has executable permissions. 
   532  	    These permissions are determined according to 
   533  	    the underlying OS.</li>
   534  
   535              <li>'<strong>-F</strong>' (is existing file, via
   536              subrequest)<br />
   537              Checks whether or not <em>TestString</em> is a valid file,
   538              accessible via all the server's currently-configured
   539              access controls for that path. This uses an internal
   540              subrequest to do the check, so use it with care -
   541              it can impact your server's performance!</li>
   542  
   543              <li><p>'<strong>-U</strong>' (is existing URL, via
   544              subrequest)<br />
   545              Checks whether or not <em>TestString</em> is a valid URL,
   546              accessible via all the server's currently-configured
   547              access controls for that path. This uses an internal
   548              subrequest to do the check, so use it with care - 
   549              it can impact your server's performance!</p>
   550              <p> This flag <em>only</em> returns information about things
   551              like access control, authentication, and authorization.  This flag
   552              <em>does not</em> return information about the status code the 
   553              configured handler (static file, CGI, proxy, etc.) would have 
   554              returned.</p> </li>
   555            </ul>
   556  
   557  <div class="note"><h3>Note:</h3>
   558                All of these tests can
   559                also be prefixed by an exclamation mark ('!') to
   560                negate their meaning.
   561  </div>
   562          </li>
   563  
   564  	<li>You can also set special flags for
   565        <em>CondPattern</em> by appending
   566          <strong><code>[</code><em>flags</em><code>]</code></strong>
   567        as the third argument to the <code>RewriteCond</code>
   568        directive, where <em>flags</em> is a comma-separated list of any of the
   569        following flags:
   570  
   571        <ul>
   572          <li>'<strong><code>nocase|NC</code></strong>'
   573          (<strong>n</strong>o <strong>c</strong>ase)<br />
   574          This makes the test case-insensitive - differences 
   575  	between 'A-Z' and 'a-z' are ignored, both in the
   576          expanded <em>TestString</em> and the <em>CondPattern</em>.
   577          This flag is effective only for comparisons between
   578          <em>TestString</em> and <em>CondPattern</em>. It has no
   579          effect on filesystem and subrequest checks.</li>
   580  
   581          <li>
   582            '<strong><code>ornext|OR</code></strong>'
   583            (<strong>or</strong> next condition)<br />
   584            Use this to combine rule conditions with a local OR
   585            instead of the implicit AND. Typical example: 
   586  
   587  <div class="example"><pre>RewriteCond %{REMOTE_HOST}  =host1  [OR]
   588  RewriteCond %{REMOTE_HOST}  =host2  [OR]
   589  RewriteCond %{REMOTE_HOST}  =host3
   590  RewriteRule ...some special stuff for any of these hosts...</pre></div>
   591  
   592            Without this flag you would have to write the condition/rule
   593            pair three times.
   594          </li>
   595  
   596          <li>'<strong><code>novary|NV</code></strong>'
   597          (<strong>n</strong>o <strong>v</strong>ary)<br />
   598          If a HTTP header is used in the condition, this flag prevents
   599          this header from being added to the Vary header of the response. <br />
   600          Using this flag might break proper caching of the response if
   601          the representation of this response varies on the value of this header.
   602          So this flag should be only used if the meaning of the Vary header
   603          is well understood.
   604          </li>
   605        </ul>
   606        </li>
   607       </ol>
   608  
   609        <p><strong>Example:</strong></p>
   610  
   611         <p>To rewrite the Homepage of a site according to the
   612          ``<code>User-Agent:</code>'' header of the request, you can
   613          use the following: </p>
   614  
   615  <div class="example"><pre>RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla
   616  RewriteRule  ^/$                 /homepage.max.html  [L]
   617  
   618  RewriteCond  %{HTTP_USER_AGENT}  ^Lynx
   619  RewriteRule  ^/$                 /homepage.min.html  [L]
   620  
   621  RewriteRule  ^/$                 /homepage.std.html  [L]</pre></div>
   622  
   623          <p>Explanation: If you use a browser which identifies itself 
   624  	as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
   625          get the max homepage (which could include frames, or other special
   626  	features).
   627          If you use the Lynx browser (which is terminal-based), then
   628  	you get the min homepage (which could be a version designed for 
   629  	easy, text-only browsing).
   630  	If neither of these conditions apply (you use any other browser,
   631  	or your browser identifies itself as something non-standard), you get
   632          the std (standard) homepage.</p>
   633  
   634  
   635  </div>
   636  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   637  <div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
   638  <table class="directive">
   639  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
   640  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
   641  <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
   642  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
   643  <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
   644  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   645  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   646  </table>       
   647  
   648        <p>The <code class="directive">RewriteEngine</code> directive enables or
   649        disables the runtime rewriting engine. If it is set to
   650        <code>off</code> this module does no runtime processing at
   651        all. It does not even update the <code>SCRIPT_URx</code>
   652        environment variables.</p>
   653  
   654        <p>Use this directive to disable the module instead of
   655        commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
   656  
   657        <p>Note that rewrite configurations are not
   658        inherited by virtual hosts. This means that you need to have a
   659        <code>RewriteEngine on</code> directive for each virtual host
   660        in which you wish to use rewrite rules.</p>
   661  
   662        <p><code class="directive">RewriteMap</code> directives of the type <code>prg</code>
   663        are not started during server initialization if they're defined in a
   664        context that does not have <code class="directive">RewriteEngine</code>  set to
   665        <code>on</code></p>
   666  
   667  </div>
   668  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   669  <div class="directive-section"><h2><a name="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">Directive</a></h2>
   670  <table class="directive">
   671  <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>
   672  synchronization</td></tr>
   673  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr>
   674  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
   675  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   676  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   677  </table>
   678        <p>This directive sets the filename for a synchronization
   679        lockfile which mod_rewrite needs to communicate with <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
   680        <em>programs</em>. Set this lockfile to a local path (not on a
   681        NFS-mounted device) when you want to use a rewriting
   682        map-program. It is not required for other types of rewriting
   683        maps.</p>
   684  
   685  </div>
   686  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   687  <div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2>
   688  <table class="directive">
   689  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
   690  processing</td></tr>
   691  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path|pipe</em></code></td></tr>
   692  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
   693  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   694  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   695  </table>
   696        <p>The <code class="directive">RewriteLog</code> directive sets the name
   697        of the file to which the server logs any rewriting actions it
   698        performs. If the name does not begin with a slash
   699        ('<code>/</code>') then it is assumed to be relative to the
   700        <em>Server Root</em>. The directive should occur only once per
   701        server config.</p>
   702  
   703  <div class="note">    To disable the logging of
   704            rewriting actions it is not recommended to set
   705            <em>Filename</em> to <code>/dev/null</code>, because
   706            although the rewriting engine does not then output to a
   707            logfile it still creates the logfile output internally.
   708            <strong>This will slow down the server with no advantage
   709            to the administrator!</strong> To disable logging either
   710            remove or comment out the <code class="directive">RewriteLog</code>
   711            directive or use <code>RewriteLogLevel 0</code>!
   712  </div>
   713  
   714      <p>The <code class="directive">RewriteLog</code> log file format is as
   715      follows:</p>
   716  
   717  <table>
   718  <tr><th>Description</th><th> Example</th></tr>
   719  <tr>
   720  <td>Remote host IP address</td>
   721  <td>192.168.200.166</td></tr>
   722  <tr><td>Remote login name</td><td>Will usually be "-"</td></tr>
   723  <tr><td>HTTP user auth name</td><td>Username, or "-" if no auth</td></tr>
   724  <tr><td>Date and time of request</td><td>[28/Aug/2009:13:09:09 --0400]</td></tr>
   725  <tr><td>Virtualhost and virtualhost ID</td><td>[www.example.com/sid#84a650]</td></tr>
   726  <tr><td>Request ID, and whether it's a subrequest</td><td>[rid#9f0e58/subreq]</td></tr>
   727  <tr><td>Log entry severity level</td><td>(2)</td></tr>
   728  <tr><td>Text error message</td><td>forcing proxy-throughput with http://127.0.0.1:8080/index.html</td></tr>
   729  </table>
   730  
   731  <div class="note"><h3>Security</h3>
   732  
   733  See the <a href="../misc/security_tips.html">Apache Security Tips</a>
   734  document for details on how your security could be compromised if the
   735  directory where logfiles are stored is writable by anyone other than
   736  the user that starts the server.
   737  </div>
   738  
   739  <div class="example"><h3>Example</h3><p><code>
   740  # Log to a file:<br />
   741  RewriteLog "/usr/local/var/apache/logs/rewrite.log"<br />
   742  <br />
   743  # Log to a pipe:<br />
   744  RewriteLog "|/path/to/parser.pl"
   745  </code></p></div>
   746  
   747  
   748  </div>
   749  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   750  <div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2>
   751  <table class="directive">
   752  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
   753  engine</td></tr>
   754  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
   755  <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
   756  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
   757  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   758  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   759  </table>
   760        <p>The <code class="directive">RewriteLogLevel</code> directive sets the
   761        verbosity level of the rewriting logfile. The default level 0
   762        means no logging, while 9 or more means that practically all
   763        actions are logged.</p>
   764  
   765        <p>To disable the logging of rewriting actions simply set
   766        <em>Level</em> to 0. This disables all rewrite action
   767        logs.</p>
   768  
   769  <div class="note"> Using a high value for
   770            <em>Level</em> will slow down your Apache server
   771            dramatically! Use the rewriting logfile at a
   772            <em>Level</em> greater than 2 only for debugging!
   773  </div>
   774  
   775  <div class="example"><h3>Example</h3><p><code>
   776  RewriteLogLevel 3
   777  </code></p></div>
   778  
   779  
   780  </div>
   781  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
   782  <div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
   783  <table class="directive">
   784  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
   785  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
   786  </code></td></tr>
   787  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
   788  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
   789  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
   790  <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
   791  Apache 2.0.41 and later</td></tr>
   792  </table>
   793        <p>The <code class="directive">RewriteMap</code> directive defines a
   794        <em>Rewriting Map</em> which can be used inside rule
   795        substitution strings by the mapping-functions to
   796        insert/substitute fields through a key lookup. The source of
   797        this lookup can be of various types.</p>
   798  
   799        <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
   800        the name of the map and will be used to specify a
   801        mapping-function for the substitution strings of a rewriting
   802        rule via one of the following constructs:</p>
   803  
   804        <p class="indent">
   805          <strong><code>${</code> <em>MapName</em> <code>:</code>
   806          <em>LookupKey</em> <code>}</code><br />
   807           <code>${</code> <em>MapName</em> <code>:</code>
   808          <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
   809          <code>}</code></strong>
   810        </p>
   811  
   812        <p>When such a construct occurs, the map <em>MapName</em> is
   813        consulted and the key <em>LookupKey</em> is looked-up. If the
   814        key is found, the map-function construct is substituted by
   815        <em>SubstValue</em>. If the key is not found then it is
   816        substituted by <em>DefaultValue</em> or by the empty string
   817        if no <em>DefaultValue</em> was specified. Empty values
   818        behave as if the key was absent, therefore it is not possible
   819        to distinguish between empty-valued keys and absent keys.</p>
   820  
   821        <p>For example, you might define a
   822        <code class="directive">RewriteMap</code> as:</p>
   823  
   824        <div class="example"><p><code>
   825        RewriteMap examplemap txt:/path/to/file/map.txt
   826        </code></p></div>
   827  
   828        <p>You would then be able to use this map in a
   829        <code class="directive">RewriteRule</code> as follows:</p>
   830  
   831        <div class="example"><p><code>
   832        RewriteRule ^/ex/(.*) ${examplemap:$1}
   833        </code></p></div>
   834  
   835        <p>The following combinations for <em>MapType</em> and
   836        <em>MapSource</em> can be used:</p>
   837  
   838        <ul>
   839          <li>
   840            <strong>Standard Plain Text</strong><br />
   841             MapType: <code>txt</code>, MapSource: Unix filesystem
   842            path to valid regular file 
   843  
   844            <p>This is the standard rewriting map feature where the
   845            <em>MapSource</em> is a plain ASCII file containing
   846            either blank lines, comment lines (starting with a '#'
   847            character) or pairs like the following - one per
   848            line.</p>
   849  
   850            <p class="indent">
   851              <strong><em>MatchingKey</em>
   852              <em>SubstValue</em></strong>
   853            </p>
   854  
   855  <div class="example"><h3>Example</h3><pre>##
   856  ##  map.txt -- rewriting map
   857  ##
   858  
   859  Ralf.S.Engelschall    rse   # Bastard Operator From Hell
   860  Mr.Joe.Average        joe   # Mr. Average</pre></div>
   861  
   862  <div class="example"><p><code>
   863  RewriteMap real-to-user txt:/path/to/file/map.txt
   864  </code></p></div>
   865          </li>
   866  
   867          <li>
   868            <strong>Randomized Plain Text</strong><br />
   869             MapType: <code>rnd</code>, MapSource: Unix filesystem
   870            path to valid regular file 
   871  
   872            <p>This is identical to the Standard Plain Text variant
   873            above but with a special post-processing feature: After
   874            looking up a value it is parsed according to contained
   875            ``<code>|</code>'' characters which have the meaning of
   876            ``or''. In other words they indicate a set of
   877            alternatives from which the actual returned value is
   878            chosen randomly. For example, you might use the following map
   879            file and directives to provide a random load balancing between
   880            several back-end servers, via a reverse-proxy. Images are sent
   881            to one of the servers in the 'static' pool, while everything
   882            else is sent to one of the 'dynamic' pool.</p>
   883            <p>Example:</p>
   884  
   885  <div class="example"><h3>Rewrite map file</h3><pre>##
   886  ##  map.txt -- rewriting map
   887  ##
   888  
   889  static   www1|www2|www3|www4
   890  dynamic  www5|www6</pre></div>
   891  
   892  <div class="example"><h3>Configuration directives</h3><p><code>
   893  RewriteMap servers rnd:/path/to/file/map.txt<br />
   894  <br />
   895  RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
   896  [NC,P,L]<br />
   897  RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
   898  </code></p></div>
   899          </li>
   900  
   901          <li>
   902            <strong>Hash File</strong><br /> MapType:
   903            <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
   904            path to valid regular file
   905  
   906            <p>Here the source is a binary format DBM file containing
   907            the same contents as a <em>Plain Text</em> format file, but
   908            in a special representation which is optimized for really
   909            fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
   910            db depending on <a href="../install.html#dbm">compile-time
   911            settings</a>.  If the <em>type</em> is omitted, the
   912            compile-time default will be chosen.</p>
   913  
   914            <p>To create a dbm file from a source text file, use the <a href="../programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
   915  
   916  <div class="example"><p><code>
   917  $ httxt2dbm -i mapfile.txt -o mapfile.map
   918  </code></p></div>
   919          </li>
   920  
   921          <li>
   922            <strong>Internal Function</strong><br />
   923             MapType: <code>int</code>, MapSource: Internal Apache
   924            function 
   925  
   926            <p>Here, the source is an internal Apache function.
   927            Module authors can provide additional internal functions by registering 
   928            them with the <code>ap_register_rewrite_mapfunc</code> API.
   929            The functions that are provided by default are:
   930            </p>
   931  
   932            <ul>
   933              <li><strong>toupper</strong>:<br />
   934               Converts the key to all upper case.</li>
   935  
   936              <li><strong>tolower</strong>:<br />
   937               Converts the key to all lower case.</li>
   938  
   939              <li><strong>escape</strong>:<br />
   940               Translates special characters in the key to
   941              hex-encodings.</li>
   942  
   943              <li><strong>unescape</strong>:<br />
   944               Translates hex-encodings in the key back to
   945              special characters.</li>
   946            </ul>
   947          </li>
   948  
   949          <li>
   950            <strong>External Rewriting Program</strong><br />
   951             MapType: <code>prg</code>, MapSource: Unix filesystem
   952            path to valid regular file 
   953  
   954            <p>Here the source is a program, not a map file. To
   955            create it you can use a language of your choice, but
   956            the result has to be an executable program (either
   957            object-code or a script with the magic cookie trick
   958            '<code>#!/path/to/interpreter</code>' as the first
   959            line).</p>
   960  
   961           <p>This program is started once, when the Apache server
   962            is started, and then communicates with the rewriting engine
   963            via its <code>stdin</code> and <code>stdout</code>
   964            file-handles. For each map-function lookup it will
   965            receive the key to lookup as a newline-terminated string
   966            on <code>stdin</code>. It then has to give back the
   967            looked-up value as a newline-terminated string on
   968            <code>stdout</code> or the four-character string
   969            ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
   970            is no corresponding value for the given key). A trivial
   971            program which will implement a 1:1 map (<em>i.e.</em>,
   972            key == value) could be:</p>
   973  
   974            <p>External rewriting programs are not started if they're defined in a
   975            context that does not have <code class="directive">RewriteEngine</code> set to
   976            <code>on</code>.</p>
   977  
   978  <div class="example"><pre>#!/usr/bin/perl
   979  $| = 1;
   980  while (&lt;STDIN&gt;) {
   981      # ...put here any transformations or lookups...
   982      print $_;
   983  }</pre></div>
   984  
   985            <p>But be very careful:</p>
   986  
   987            <ol>
   988              <li>``<em>Keep it simple, stupid</em>'' (KISS).
   989  	    If this program hangs, it will cause Apache to hang 
   990  	    when trying to use the relevant rewrite rule.</li>
   991  
   992              <li>A common mistake is to use buffered I/O on
   993              <code>stdout</code>. Avoid this, as it will cause a deadloop!
   994              ``<code>$|=1</code>'' is used above, to prevent this.</li>
   995  
   996              <li>The <code class="directive"><a href="#rewritelock">RewriteLock</a></code> directive can 
   997  	    be used to define a lockfile which mod_rewrite can use to synchronize 
   998              communication with the mapping program. By default no such
   999              synchronization takes place.</li>
  1000            </ol>
  1001          </li>
  1002        </ul>
  1003        <p>The <code class="directive">RewriteMap</code> directive can occur more than
  1004        once. For each mapping-function use one
  1005        <code class="directive">RewriteMap</code> directive to declare its rewriting
  1006        mapfile. While you cannot <strong>declare</strong> a map in
  1007        per-directory context it is of course possible to
  1008        <strong>use</strong> this map in per-directory context. </p>
  1009  
  1010  <div class="note"><h3>Note</h3> For plain text and DBM format files the
  1011  looked-up keys are cached in-core until the <code>mtime</code> of the
  1012  mapfile changes or the server does a restart. This way you can have
  1013  map-functions in rules which are used for <strong>every</strong>
  1014  request.  This is no problem, because the external lookup only happens
  1015  once!
  1016  </div>
  1017  
  1018  
  1019  </div>
  1020  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  1021  <div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
  1022  <table class="directive">
  1023  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
  1024  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></code></td></tr>
  1025  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
  1026  <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
  1027  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
  1028  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
  1029  <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
  1030  later</td></tr>
  1031  </table>
  1032  
  1033        <p>The <code class="directive">RewriteOptions</code> directive sets some
  1034        special options for the current per-server or per-directory
  1035        configuration. The <em>Option</em> string can currently 
  1036        only be one of the following:</p>
  1037  
  1038        <dl>
  1039        <dt><code>inherit</code></dt>
  1040        <dd>
  1041        
  1042        <p>This forces the current configuration to inherit the
  1043        configuration of the parent. In per-virtual-server context,
  1044        this means that the maps, conditions and rules of the main
  1045        server are inherited. In per-directory context this means
  1046        that conditions and rules of the parent directory's
  1047        <code>.htaccess</code> configuration are inherited.</p>
  1048  
  1049        <div class="warning">
  1050        Rules inherited from the parent scope are applied
  1051        <strong>after</strong> rules specified in the child scope.
  1052        </div>
  1053        
  1054        </dd>
  1055  
  1056        <dt><code>AllowAnyURI</code></dt>
  1057        <dd>
  1058  
  1059        <p>When <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
  1060        is used in <code>VirtualHost</code> or server context with
  1061        version 2.2.23 or later of httpd, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
  1062        will only process the rewrite rules if the request URI is a <a href="./directive-dict.html#Syntax">URL-path</a>.  This avoids
  1063        some security issues where particular rules could allow
  1064        "surprising" pattern expansions (see <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
  1065        and <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
  1066        To lift the restriction on matching a URL-path, the
  1067        <code>AllowAnyURI</code> option can be enabled, and
  1068        <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> will apply the rule set to any
  1069        request URI string, regardless of whether that string matches
  1070        the URL-path grammar required by the HTTP specification.</p>
  1071  
  1072        <div class="warning">
  1073        <h3>Security Warning</h3> 
  1074  
  1075        <p>Enabling this option will make the server vulnerable to
  1076        security issues if used with rewrite rules which are not
  1077        carefully authored.  It is <strong>strongly recommended</strong>
  1078        that this option is not used.  In particular, beware of input
  1079        strings containing the '<code>@</code>' character which could
  1080        change the interpretation of the transformed URI, as per the
  1081        above CVE names.</p>
  1082        </div>
  1083        </dd>
  1084  
  1085        <dt><code>MergeBase</code></dt>
  1086        <dd>
  1087  
  1088        <p>With this option, the value of <code class="directive"><a href="#rewritebase">RewriteBase</a></code> is copied from where it's explicitly defined
  1089        into any sub-directory or sub-location that doesn't define its own
  1090        <code class="directive"><a href="#rewritebase">RewriteBase</a></code>. Not copying
  1091        was the default until 2.2.22. In version 2.2.23 copying was the default.
  1092        The flag to explicitly control it is available for Apache HTTP
  1093        Server 2.2.24 and later.</p>
  1094        </dd>
  1095        </dl>
  1096  
  1097  
  1098  </div>
  1099  <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  1100  <div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
  1101  <table class="directive">
  1102  <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
  1103  <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteRule
  1104        <em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</code></td></tr>
  1105  <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
  1106  <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
  1107  <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
  1108  <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
  1109  </table>
  1110        <p>The <code class="directive">RewriteRule</code> directive is the real
  1111        rewriting workhorse. The directive can occur more than once,
  1112        with each instance defining a single rewrite rule. The
  1113        order in which these rules are defined is important - this is the order
  1114        in which they will be applied at run-time.</p>
  1115  
  1116        <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
  1117        a perl compatible <a id="regexp" name="regexp">regular
  1118        expression</a>. On the first RewriteRule it is applied to the (%-decoded)
  1119        <a href="./directive-dict.html#Syntax">URL-path</a> of the request;
  1120        subsequent patterns are applied to the output of the last matched
  1121        RewriteRule.</p>
  1122  
  1123  <div class="note"><h3>What is matched?</h3>
  1124        <p>In <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> context, 
  1125        The <em>Pattern</em> will initially be matched against the part of the
  1126        URL after the hostname and port, and before the query string (e.g. "/app1/index.html").</p>
  1127  
  1128        <p>In <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> and htaccess context,
  1129        the <em>Pattern</em> will initially be matched against the  
  1130        <em>filesystem</em> path, after removing the prefix that led the server
  1131        to the current <code class="directive">RewriteRule</code> (e.g. "app1/index.html" 
  1132        or "index.html" depending on where the directives are defined).</p>
  1133         
  1134        <p>If you wish to match against the hostname, port, or query string, use a
  1135        <code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
  1136        <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
  1137        <code>%{QUERY_STRING}</code> variables respectively.</p>
  1138  
  1139  </div>
  1140  
  1141  <div class="note"><h3>Per-directory Rewrites</h3>
  1142  <ul>
  1143  <li>The rewrite engine may be used in <a href="../howto/htaccess.html">.htaccess</a> files and in <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code> sections, with some additional
  1144  complexity.</li>
  1145  
  1146  <li>To enable the rewrite engine in this context, you need to set
  1147  "<code>RewriteEngine On</code>" <strong>and</strong>
  1148  "<code>Options FollowSymLinks</code>" must be enabled. If your
  1149  administrator has disabled override of <code>FollowSymLinks</code> for
  1150  a user's directory, then you cannot use the rewrite engine. This
  1151  restriction is required for security reasons.</li>
  1152  
  1153  <li>When using the rewrite engine in <code>.htaccess</code> files the
  1154  per-directory prefix (which always is the same for a specific
  1155  directory) is automatically <em>removed</em> for the RewriteRule pattern matching
  1156  and automatically <em>added</em> after any relative (not starting with a
  1157  slash or protocol name) substitution encounters the end of a rule set.  
  1158  See the <code class="directive"><a href="#rewritebase">RewriteBase</a></code> 
  1159  directive for more information regarding what prefix will be added back to 
  1160  relative substitutions.</li>
  1161  
  1162  <li> If you wish to match against the full URL-path in a per-directory 
  1163  (htaccess) RewriteRule, use the <code>%{REQUEST_URI}</code> variable in
  1164  a <code class="directive">RewriteCond</code>.</li>
  1165  
  1166  <li>The removed prefix always ends with a slash, meaning the matching occurs against a string which
  1167  <em>never</em> has a leading slash.  Therefore, a <em>Pattern</em> with <code>^/</code> never
  1168  matches in per-directory context.</li>
  1169  
  1170  <li>Although rewrite rules are syntactically permitted in <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code> and <code class="directive"><a href="../mod/core.html#files">&lt;Files&gt;</a></code> sections, this
  1171  should never be necessary and is unsupported.</li>
  1172  </ul>
  1173  </div>
  1174  
  1175        <p>For some hints on <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular
  1176        expressions</a>, see
  1177        the <a href="../rewrite/intro.html#regex">mod_rewrite
  1178        Introduction</a>.</p>
  1179  
  1180        <p>In mod_rewrite, the NOT character
  1181        ('<code>!</code>') is also available as a possible pattern
  1182        prefix. This enables you to negate a pattern; to say, for instance:
  1183        ``<em>if the current URL does <strong>NOT</strong> match this
  1184        pattern</em>''. This can be used for exceptional cases, where
  1185        it is easier to match the negative pattern, or as a last
  1186        default rule.</p>
  1187  
  1188  
  1189  <div class="note"><h3>Note</h3>
  1190  When using the NOT character to negate a pattern, you cannot include 
  1191  grouped wildcard parts in that pattern. This is because, when the 
  1192  pattern does NOT match (ie, the negation matches), there are no 
  1193  contents for the groups. Thus, if negated patterns are used, you
  1194  cannot use <code>$N</code> in the substitution string!
  1195  </div>
  1196  
  1197        <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
  1198        rewrite rule is the string that replaces the original URL-path that
  1199        was matched by <em>Pattern</em>.  The <em>Substitution</em> may
  1200        be a:</p>
  1201  
  1202        <dl>
  1203  
  1204          <dt>file-system path</dt>
  1205  
  1206          <dd>Designates the location on the file-system of the resource
  1207          to be delivered to the client.  Substitutions are only
  1208          treated as a file-system path when the rule is configured in 
  1209          server (virtualhost) context and the first component of the
  1210          path in the substitution is exists in the file-system</dd>
  1211  
  1212          <dt>URL-path</dt> 
  1213  
  1214          <dd>A <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>-relative path to the
  1215          resource to be served. Note that <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
  1216          tries to guess whether you have specified a file-system path
  1217          or a URL-path by checking to see if the first segment of the
  1218          path exists at the root of the file-system. For example, if
  1219          you specify a <em>Substitution</em> string of
  1220          <code>/www/file.html</code>, then this will be treated as a
  1221          URL-path <em>unless</em> a directory named <code>www</code>
  1222          exists at the root or your file-system (or, in the case of 
  1223          using rewrites in a <code>.htaccess</code> file, relative to
  1224          your document root), in which case it will
  1225          be treated as a file-system path. If you wish other
  1226          URL-mapping directives (such as <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
  1227          resulting URL-path, use the <code>[PT]</code> flag as
  1228          described below.</dd>
  1229  
  1230          <dt>Absolute URL</dt>
  1231  
  1232          <dd>If an absolute URL is specified,
  1233          <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
  1234          hostname matches the current host. If it does, the scheme and
  1235          hostname are stripped out and the resulting path is treated as
  1236          a URL-path. Otherwise, an external redirect is performed for
  1237          the given URL. To force an external redirect back to the
  1238          current host, see the <code>[R]</code> flag below.</dd>
  1239  
  1240          <dt><code>-</code> (dash)</dt>
  1241  
  1242          <dd>A dash indicates that no substitution should be performed
  1243          (the existing path is passed through untouched). This is used
  1244          when a flag (see below) needs to be applied without changing
  1245          the path.</dd>
  1246  
  1247        </dl>
  1248  
  1249        <p>In addition to plain text, the <em>Substition</em> string can include</p>
  1250  
  1251        <ol>
  1252          <li>back-references (<code>$N</code>) to the RewriteRule
  1253          pattern</li>
  1254  
  1255          <li>back-references (<code>%N</code>) to the last matched
  1256          RewriteCond pattern</li>
  1257  
  1258          <li>server-variables as in rule condition test-strings
  1259          (<code>%{VARNAME}</code>)</li>
  1260  
  1261          <li><a href="#mapfunc">mapping-function</a> calls
  1262          (<code>${mapname:key|default}</code>)</li>
  1263        </ol>
  1264  
  1265        <p>Back-references are identifiers of the form 
  1266  	      <code>$</code><strong>N</strong>
  1267        (<strong>N</strong>=0..9), which will be replaced
  1268        by the contents of the <strong>N</strong>th group of the
  1269        matched <em>Pattern</em>. The server-variables are the same
  1270        as for the <em>TestString</em> of a <code>RewriteCond</code>
  1271        directive. The mapping-functions come from the
  1272        <code>RewriteMap</code> directive and are explained there.
  1273        These three types of variables are expanded in the order above.</p>
  1274  
  1275        <p>Rewrite rules are applied to the results of previous rewrite
  1276        rules, in the order in which they are defined in the config file.
  1277        The URL is  <strong>completely
  1278        replaced</strong> by the <em>Substitution</em> and the
  1279        rewriting process continues until all rules have been applied,
  1280        or it is explicitly terminated by a
  1281        <a href="../rewrite/flags.html#flag_l"><code><strong>L</strong></code> flag</a>,
  1282        or other flag which implies immediate termination, such as
  1283        <code><strong>F</strong></code>.</p>
  1284   
  1285       <div class="note"><h3>Modifying the Query String</h3>
  1286        <p>By default, the query string is passed through unchanged. You
  1287        can, however, create URLs in the substitution string containing
  1288        a query string part. Simply use a question mark inside the
  1289        substitution string to indicate that the following text should
  1290        be re-injected into the query string. When you want to erase an
  1291        existing query string, end the substitution string with just a
  1292        question mark. To combine new and old query strings, use the
  1293        <code>[QSA]</code> flag.</p> 
  1294       </div>
  1295  
  1296        <p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
  1297        appending <strong><code>[</code><em>flags</em><code>]</code></strong>
  1298        as the third argument to the <code>RewriteRule</code>
  1299        directive. <em>Flags</em> is a comma-separated list, surround by square
  1300        brackets, of any of the flags in the following table. More
  1301        details, and examples, for each flag, are available in the <a href="../rewrite/flags.html">Rewrite Flags document</a>.</p>
  1302  
  1303      <table class="bordered">
  1304      <tr><th>Flag and syntax</th>
  1305          <th>Function</th>
  1306      </tr>
  1307      <tr>
  1308          <td>B</td>
  1309          <td>Escape non-alphanumeric characters <em>before</em> applying
  1310          the transformation. <em><a href="../rewrite/flags.html#flag_b">details ...</a></em></td>
  1311      </tr>
  1312      <tr>
  1313          <td>chain|C</td>
  1314          <td>Rule is chained to the following rule. If the rule fails,
  1315          the rule(s) chained to it will be skipped. <em><a href="../rewrite/flags.html#flag_c">details ...</a></em></td>
  1316      </tr>
  1317      <tr>
  1318          <td>cookie|CO=<em>NAME</em>:<em>VAL</em></td>
  1319          <td>Sets a cookie in the client browser. Full syntax is: 
  1320          CO=<em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]] <em><a href="../rewrite/flags.html#flag_co">details ...</a></em>
  1321          </td>
  1322      </tr>
  1323      <tr>
  1324          <td>discardpath|DPI</td>
  1325          <td>Causes the PATH_INFO portion of the rewritten URI to be
  1326          discarded. <em><a href="../rewrite/flags.html#flag_dpi">details 
  1327          ...</a></em></td>
  1328      </tr>
  1329      <tr>
  1330          <td>env|E=[!]<em>VAR</em>[:<em>VAL</em>]</td>
  1331          <td>Causes an environment variable <em>VAR</em> to be set (to the
  1332          value <em>VAL</em> if provided). The form !<em>VAR</em> causes
  1333          the environment variable <em>VAR</em> to be unset.<em><a href="../rewrite/flags.html#flag_e">details ...</a></em></td>
  1334      </tr>
  1335      <tr>
  1336          <td>forbidden|F</td>
  1337          <td>Returns a 403 FORBIDDEN response to the client browser.
  1338          <em><a href="../rewrite/flags.html#flag_f">details ...</a></em></td>
  1339      </tr>
  1340      <tr>
  1341          <td>gone|G</td>
  1342          <td>Returns a 410 GONE response to the client browser. <em><a href="../rewrite/flags.html#flag_g">details ...</a></em></td>
  1343      </tr>
  1344      <tr>
  1345          <td>Handler|H=<em>Content-handler</em></td>
  1346          <td>Causes the resulting URI to be sent to the specified
  1347          <em>Content-handler</em> for processing. <em><a href="../rewrite/flags.html#flag_h">details ...</a></em></td>
  1348      </tr>
  1349      <tr>
  1350          <td>last|L</td>
  1351          <td>Stop the rewriting process immediately and don't apply any
  1352          more rules. Especially note caveats for per-directory and
  1353          .htaccess context. <em><a href="../rewrite/flags.html#flag_l">details ...</a></em></td>
  1354      </tr>
  1355      <tr>
  1356          <td>next|N</td>
  1357          <td>Re-run the rewriting process, starting again with the first
  1358          rule, using the result of the ruleset so far as a starting
  1359          point. <em><a href="../rewrite/flags.html#flag_n">details
  1360          ...</a></em></td>
  1361      </tr>
  1362      <tr>
  1363          <td>nocase|NC</td>
  1364          <td>Makes the pattern comparison case-insensitive.
  1365          <em><a href="../rewrite/flags.html#flag_nc">details ...</a></em></td>
  1366      </tr>
  1367      <tr>
  1368          <td>noescape|NE</td>
  1369          <td>Prevent mod_rewrite from applying hexcode escaping of
  1370          special characters in the result of the rewrite. <em><a href="../rewrite/flags.html#flag_ne">details ...</a></em></td>
  1371      </tr>
  1372      <tr>
  1373          <td>nosubreq|NS</td>
  1374          <td>Causes a rule to be skipped if the current request is an
  1375          internal sub-request. <em><a href="../rewrite/flags.html#flag_ns">details ...</a></em></td>
  1376      </tr>
  1377      <tr>
  1378          <td>proxy|P</td>
  1379          <td>Force the substitution URL to be internally sent as a proxy
  1380          request. <em><a href="../rewrite/flags.html#flag_p">details
  1381          ...</a></em></td>
  1382      </tr>
  1383      <tr>
  1384          <td>passthrough|PT</td>
  1385          <td>Forces the resulting URI to be passed back to the URL
  1386          mapping engine for processing of other URI-to-filename
  1387          translators, such as <code>Alias</code> or
  1388          <code>Redirect</code>. <em><a href="../rewrite/flags.html#flag_pt">details ...</a></em></td>
  1389      </tr>
  1390      <tr>
  1391          <td>qsappend|QSA</td>
  1392          <td>Appends any query string from the original request URL to 
  1393          any query string created in the rewrite target.<em><a href="../rewrite/flags.html#flag_qsa">details ...</a></em></td>
  1394      </tr>
  1395      <tr>
  1396          <td>redirect|R[=<em>code</em>]</td>
  1397          <td>Forces an external redirect, optionally with the specified
  1398          HTTP status code. <em><a href="../rewrite/flags.html#flag_r">details ...</a></em>
  1399          </td>
  1400      </tr>
  1401      <tr>
  1402          <td>skip|S=<em>num</em></td>
  1403          <td>Tells the rewriting engine to skip the next <em>num</em>
  1404          rules if the current rule matches. <em><a href="../rewrite/flags.html#flag_s">details ...</a></em></td>
  1405      </tr>
  1406      <tr>
  1407          <td>type|T=<em>MIME-type</em></td>
  1408          <td>Force the <a class="glossarylink" href="../glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file
  1409          to be the specified type. <em><a href="../rewrite/flags.html#flag_t">details ...</a></em></td>
  1410      </tr>
  1411      </table>
  1412  
  1413  <div class="note"><h3>Home directory expansion</h3>
  1414  <p> When the substitution string begins with a string
  1415  resembling "/~user" (via explicit text or backreferences), mod_rewrite performs
  1416  home directory expansion independent of the presence or configuration
  1417  of <code class="module"><a href="../mod/mod_userdir.html">mod_userdir</a></code>.</p>
  1418  
  1419  <p> This expansion does not occur when the <em>PT</em>
  1420  flag is used on the <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
  1421  directive.</p>
  1422  </div>
  1423  
  1424       <p>Here are all possible substitution combinations and their
  1425        meanings:</p>
  1426  
  1427        <p><strong>Inside per-server configuration
  1428        (<code>httpd.conf</code>)<br />
  1429         for request ``<code>GET
  1430        /somepath/pathinfo</code>'':</strong><br />
  1431        </p>
  1432  
  1433  <div class="note"><pre>
  1434  <strong>Given Rule</strong>                                      <strong>Resulting Substitution</strong>
  1435  ----------------------------------------------  ----------------------------------
  1436  ^/somepath(.*) otherpath$1                      invalid, not supported
  1437  
  1438  ^/somepath(.*) otherpath$1  [R]                 invalid, not supported
  1439  
  1440  ^/somepath(.*) otherpath$1  [P]                 invalid, not supported
  1441  ----------------------------------------------  ----------------------------------
  1442  ^/somepath(.*) /otherpath$1                     /otherpath/pathinfo
  1443  
  1444  ^/somepath(.*) /otherpath$1 [R]                 http://thishost/otherpath/pathinfo
  1445                                                  via external redirection
  1446  
  1447  ^/somepath(.*) /otherpath$1 [P]                 doesn't make sense, not supported
  1448  ----------------------------------------------  ----------------------------------
  1449  ^/somepath(.*) http://thishost/otherpath$1      /otherpath/pathinfo
  1450  
  1451  ^/somepath(.*) http://thishost/otherpath$1 [R]  http://thishost/otherpath/pathinfo
  1452                                                  via external redirection
  1453  
  1454  ^/somepath(.*) http://thishost/otherpath$1 [P]  doesn't make sense, not supported
  1455  ----------------------------------------------  ----------------------------------
  1456  ^/somepath(.*) http://otherhost/otherpath$1     http://otherhost/otherpath/pathinfo
  1457                                                  via external redirection
  1458  
  1459  ^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
  1460                                                  via external redirection
  1461                                                  (the [R] flag is redundant)
  1462  
  1463  ^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
  1464                                                  via internal proxy</pre></div>
  1465  
  1466        <p><strong>Inside per-directory configuration for
  1467        <code>/somepath</code><br />
  1468         (<code>/physical/path/to/somepath/.htaccess</code>, with
  1469        <code>RewriteBase /somepath</code>)<br />
  1470         for request ``<code>GET
  1471        /somepath/localpath/pathinfo</code>'':</strong><br /> 
  1472       </p>
  1473  
  1474  <div class="note"><pre>
  1475  <strong>Given Rule</strong>                                      <strong>Resulting Substitution</strong>
  1476  ----------------------------------------------  ----------------------------------
  1477  ^localpath(.*) otherpath$1                      /somepath/otherpath/pathinfo
  1478  
  1479  ^localpath(.*) otherpath$1  [R]                 http://thishost/somepath/otherpath/pathinfo
  1480                                                  via external redirection
  1481  
  1482  ^localpath(.*) otherpath$1  [P]                 doesn't make sense, not supported
  1483  ----------------------------------------------  ----------------------------------
  1484  ^localpath(.*) /otherpath$1                     /otherpath/pathinfo
  1485  
  1486  ^localpath(.*) /otherpath$1 [R]                 http://thishost/otherpath/pathinfo
  1487                                                  via external redirection
  1488  
  1489  ^localpath(.*) /otherpath$1 [P]                 doesn't make sense, not supported
  1490  ----------------------------------------------  ----------------------------------
  1491  ^localpath(.*) http://thishost/otherpath$1      /otherpath/pathinfo
  1492  
  1493  ^localpath(.*) http://thishost/otherpath$1 [R]  http://thishost/otherpath/pathinfo
  1494                                                  via external redirection
  1495  
  1496  ^localpath(.*) http://thishost/otherpath$1 [P]  doesn't make sense, not supported
  1497  ----------------------------------------------  ----------------------------------
  1498  ^localpath(.*) http://otherhost/otherpath$1     http://otherhost/otherpath/pathinfo
  1499                                                  via external redirection
  1500  
  1501  ^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
  1502                                                  via external redirection
  1503                                                  (the [R] flag is redundant)
  1504  
  1505  ^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
  1506                                                  via internal proxy</pre></div>
  1507    
  1508  </div>
  1509  </div>
  1510  <div class="bottomlang">
  1511  <p><span>Available Languages: </span><a href="../en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
  1512  <a href="../fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
  1513  </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
  1514  <script type="text/javascript"><!--//--><![CDATA[//><!--
  1515  var comments_shortname = 'httpd';
  1516  var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html';
  1517  (function(w, d) {
  1518      if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
  1519          d.write('<div id="comments_thread"><\/div>');
  1520          var s = d.createElement('script');
  1521          s.type = 'text/javascript';
  1522          s.async = true;
  1523          s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
  1524          (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
  1525      }
  1526      else { 
  1527          d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
  1528      }
  1529  })(window, document);
  1530  //--><!]]></script></div><div id="footer">
  1531  <p class="apache">Copyright 2017 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
  1532  <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
  1533  if (typeof(prettyPrint) !== 'undefined') {
  1534      prettyPrint();
  1535  }
  1536  //--><!]]></script>
  1537  </body></html>