mod_rewrite.html.en revision cea021a7fc2657b091df4d3b031c4254ec371dd7
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<?xml version="1.0" encoding="ISO-8859-1"?>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick This file is generated from xml source: DO NOT EDIT
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick -->
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<title>mod_rewrite - Apache HTTP Server</title>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<link href="/images/favicon.ico" rel="shortcut icon" /></head>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<body>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<div id="page-header">
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<p class="apache">Apache HTTP Server Version 2.3</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<img alt="" src="/images/feather.gif" /></div>
fb18194cd0e59b737cc179eb2354a2dcd16087d4trawick<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div id="path">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<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.3</a> &gt; <a href="./">Modules</a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div id="page-content">
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div id="preamble"><h1>Apache Module mod_rewrite</h1>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div class="toplang">
61a4b32b1032d530e84e1131cb803f803acf7461trawick<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick</div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawickURLs on the fly</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr></table>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<h3>Summary</h3>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>The <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> module uses a rule-based rewriting
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick engine, based on a regular-expression parser, to rewrite requested URLs on
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick the fly. By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> maps a URL to a filesystem
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick path. However, it can also be used to redirect one URL to another URL, or
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick to invoke an internal proxy fetch.</p>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> provides a flexible and powerful way to
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick manipulate URLs using an unlimited number of rules. Each rule can have an
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick unlimited number of attached rule conditions, to allow you to rewrite URL
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick based on server variables, environment variables, HTTP headers, or time
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick stamps.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> operates on the full URL path, including the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick path-info section. A rewrite rule can be invoked in
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick by a rewrite rule can include a query string, or can lead to internal
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick sub-processing, external request redirection, or internal proxy
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick throughput.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>Further details, discussion, and examples, are provided in the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick</div>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<div id="quickview"><h3 class="directives">Directives</h3>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<ul id="toc">
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
798cfee8074b529042079c77eee6962a723350detrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick</ul>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick</div>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
798cfee8074b529042079c77eee6962a723350detrawick<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick<table class="directive">
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
798cfee8074b529042079c77eee6962a723350detrawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick</table>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>The <code class="directive">RewriteBase</code> directive explicitly
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick sets the base URL-path (not filesystem directory path!) for per-directory rewrites.
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick When you use a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick in a <code>.htaccess</code> file, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> strips off
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick the local directory prefix before processing, then rewrites the rest of
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick the URL. When the rewrite is completed, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick automatically adds the local directory prefix back on to the path.</p>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <p>This directive is <em>required</em> for per-directory rewrites whose context
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick is a directory made available via the <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick directive.</p>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <p>If your URL path does not exist verbatim on the filesystem,
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick or isn't directly under your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>,
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick you must use <code class="directive">RewriteBase</code> in every
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <code>.htaccess</code> file where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.</p>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <p>The example below demonstrates how to map
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick http://example.com/myapp/index.html to
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick /home/www/example/newsite.html, in a <code>.htaccess</code> file. This
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick assumes that the content available at
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick http://example.com/ is on disk at /home/www/example/</p>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick<div class="example"><pre>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawickRewriteEngine On
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick# The URL-path used to get to this context, not the filesystem path
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawickRewriteBase /myapp/
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawickRewriteRule ^index\.html$ newsite.html
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick</pre></div>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick</div>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<table class="directive">
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
61a4b32b1032d530e84e1131cb803f803acf7461trawick</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
61a4b32b1032d530e84e1131cb803f803acf7461trawick <em>TestString</em> <em>CondPattern</em></code></td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick</table>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>The <code class="directive">RewriteCond</code> directive defines a
61a4b32b1032d530e84e1131cb803f803acf7461trawick rule condition. One or more <code class="directive">RewriteCond</code>
61a4b32b1032d530e84e1131cb803f803acf7461trawick can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
61a4b32b1032d530e84e1131cb803f803acf7461trawick directive. The following rule is then only used if both
61a4b32b1032d530e84e1131cb803f803acf7461trawick the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p><em>TestString</em> is a string which can contain the
61a4b32b1032d530e84e1131cb803f803acf7461trawick following expanded constructs in addition to plain text:</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick
61a4b32b1032d530e84e1131cb803f803acf7461trawick <ul>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <strong>RewriteRule backreferences</strong>: These are
61a4b32b1032d530e84e1131cb803f803acf7461trawick backreferences of the form <strong><code>$N</code></strong>
61a4b32b1032d530e84e1131cb803f803acf7461trawick (0 &lt;= N &lt;= 9). $1 to $9 provide access to the grouped
61a4b32b1032d530e84e1131cb803f803acf7461trawick parts (in parentheses) of the pattern, from the
61a4b32b1032d530e84e1131cb803f803acf7461trawick <code>RewriteRule</code> which is subject to the current
61a4b32b1032d530e84e1131cb803f803acf7461trawick set of <code>RewriteCond</code> conditions. $0 provides
61a4b32b1032d530e84e1131cb803f803acf7461trawick access to the whole string matched by that pattern.
61a4b32b1032d530e84e1131cb803f803acf7461trawick </li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <strong>RewriteCond backreferences</strong>: These are
61a4b32b1032d530e84e1131cb803f803acf7461trawick backreferences of the form <strong><code>%N</code></strong>
61a4b32b1032d530e84e1131cb803f803acf7461trawick (0 &lt;= N &lt;= 9). %1 to %9 provide access to the grouped
61a4b32b1032d530e84e1131cb803f803acf7461trawick parts (again, in parentheses) of the pattern, from the last matched
61a4b32b1032d530e84e1131cb803f803acf7461trawick <code>RewriteCond</code> in the current set
61a4b32b1032d530e84e1131cb803f803acf7461trawick of conditions. %0 provides access to the whole string matched by
61a4b32b1032d530e84e1131cb803f803acf7461trawick that pattern.
61a4b32b1032d530e84e1131cb803f803acf7461trawick </li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <strong>RewriteMap expansions</strong>: These are
61a4b32b1032d530e84e1131cb803f803acf7461trawick expansions of the form <strong><code>${mapname:key|default}</code></strong>.
61a4b32b1032d530e84e1131cb803f803acf7461trawick See <a href="#mapfunc">the documentation for
61a4b32b1032d530e84e1131cb803f803acf7461trawick RewriteMap</a> for more details.
61a4b32b1032d530e84e1131cb803f803acf7461trawick </li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <li>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <strong>Server-Variables</strong>: These are variables of
61a4b32b1032d530e84e1131cb803f803acf7461trawick the form
61a4b32b1032d530e84e1131cb803f803acf7461trawick <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <code>}</code></strong>
61a4b32b1032d530e84e1131cb803f803acf7461trawick where <em>NAME_OF_VARIABLE</em> can be a string taken
61a4b32b1032d530e84e1131cb803f803acf7461trawick from the following list:
61a4b32b1032d530e84e1131cb803f803acf7461trawick
61a4b32b1032d530e84e1131cb803f803acf7461trawick <table>
61a4b32b1032d530e84e1131cb803f803acf7461trawick
61a4b32b1032d530e84e1131cb803f803acf7461trawick <tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <th>HTTP headers:</th> <th>connection &amp; request:</th> <th />
61a4b32b1032d530e84e1131cb803f803acf7461trawick </tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick
61a4b32b1032d530e84e1131cb803f803acf7461trawick <tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <td>
61a4b32b1032d530e84e1131cb803f803acf7461trawick HTTP_USER_AGENT<br />
61a4b32b1032d530e84e1131cb803f803acf7461trawick HTTP_REFERER<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick HTTP_COOKIE<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick HTTP_FORWARDED<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick HTTP_HOST<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick HTTP_PROXY_CONNECTION<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick HTTP_ACCEPT<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </td>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick <td>
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REMOTE_ADDR<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REMOTE_HOST<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REMOTE_PORT<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REMOTE_USER<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REMOTE_IDENT<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick REQUEST_METHOD<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick SCRIPT_FILENAME<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick PATH_INFO<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick QUERY_STRING<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick AUTH_TYPE<br />
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick </td>
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick <td />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick <tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick DOCUMENT_ROOT<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick SERVER_ADMIN<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick SERVER_NAME<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick SERVER_ADDR<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick SERVER_PORT<br />
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick SERVER_PROTOCOL<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick SERVER_SOFTWARE<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_YEAR<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_MON<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_DAY<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_HOUR<br />
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick TIME_MIN<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_SEC<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME_WDAY<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick TIME<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick API_VERSION<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick THE_REQUEST<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick REQUEST_URI<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick REQUEST_FILENAME<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick IS_SUBREQ<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick HTTPS<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </td>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </table>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>These variables all
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick correspond to the similarly named HTTP
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick MIME-headers, C variables of the Apache HTTP Server or
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick <code>struct tm</code> fields of the Unix system.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick Most are documented elsewhere in the Manual or in
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the CGI specification. Those that are special to
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick mod_rewrite include those below.</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <div class="note">
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dl>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>IS_SUBREQ</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>Will contain the text "true" if the request
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick currently being processed is a sub-request,
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick "false" otherwise. Sub-requests may be generated
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick by modules that need to resolve additional files
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick or URIs in order to complete their tasks.</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>API_VERSION</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>This is the version of the Apache httpd module API
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick (the internal interface between server and
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick module) in the current httpd build, as defined in
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick include/ap_mmn.h. The module API version
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick corresponds to the version of Apache httpd in use (in
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the release version of Apache httpd 1.3.14, for
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick instance, it is 19990320:10), but is mainly of
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick interest to module authors.</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>THE_REQUEST</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>The full HTTP request line sent by the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick browser to the server (e.g., "<code>GET
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick /index.html HTTP/1.1</code>"). This does not
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick include any additional headers sent by the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick browser.</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>REQUEST_URI</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>The resource requested in the HTTP request
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick line. (In the example above, this would be
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick "/index.html".)</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>REQUEST_FILENAME</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>The full local filesystem path to the file or
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick script matching the request, if this has already
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick been determined by the server at the time
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>REQUEST_FILENAME</code> is referenced. Otherwise,
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick such as when used in virtual host context, the same
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick value as <code>REQUEST_URI</code>.</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dt><code>HTTPS</code></dt>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <dd>Will contain the text "on" if the connection is
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick using SSL/TLS, or "off" otherwise. (This variable
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick can be safely used regardless of whether or not
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded).</dd>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </dl>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick</div>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </li>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick </ul>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>Other things you should be aware of:</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <ol>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <li>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>The variables SCRIPT_FILENAME and REQUEST_FILENAME
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick contain the same value - the value of the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>filename</code> field of the internal
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick <code>request_rec</code> structure of the Apache HTTP Server.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick The first name is the commonly known CGI variable name
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick while the second is the appropriate counterpart of
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick REQUEST_URI (which contains the value of the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>uri</code> field of <code>request_rec</code>).</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>If a substitution occurred and the rewriting continues,
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the value of both variables will be updated accordingly.</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>If used in per-server context (<em>i.e.</em>, before the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick request is mapped to the filesystem) SCRIPT_FILENAME and
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick REQUEST_FILENAME cannot contain the full local filesystem
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick path since the path is unknown at this stage of processing.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick Both variables will initially contain the value of REQUEST_URI
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick in that case. In order to obtain the full local filesystem
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick path of the request in per-server context, use an URL-based
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the final value of REQUEST_FILENAME.</p></li>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <li>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <code>%{ENV:variable}</code>, where <em>variable</em> can be
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick any environment variable, is also available.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick This is looked-up via internal
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Apache httpd structures and (if not found there) via
8b69a6447203b4cbd4c063010092dbe931503644trawick <code>getenv()</code> from the Apache httpd server process.</li>
8b69a6447203b4cbd4c063010092dbe931503644trawick
8b69a6447203b4cbd4c063010092dbe931503644trawick <li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{SSL:variable}</code>, where <em>variable</em> is the
61a4b32b1032d530e84e1131cb803f803acf7461trawick name of an <a href="mod_ssl.html#envvars">SSL environment
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick variable</a>, can be used whether or not
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded, but will always expand to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the empty string if it is not. Example:
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>128</code>.</li>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{HTTP:header}</code>, where <em>header</em> can be
61a4b32b1032d530e84e1131cb803f803acf7461trawick any HTTP MIME-header name, can always be used to obtain the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick value of a header sent in the HTTP request.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Example: <code>%{HTTP:Proxy-Connection}</code> is
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the value of the HTTP header
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick ``<code>Proxy-Connection:</code>''.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>If a HTTP header is used in a condition this header is added to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the Vary header of the response in case the condition evaluates to
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick to true for the request. It is <strong>not</strong> added if the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick condition evaluates to false for the request. Adding the HTTP header
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick to the Vary header of the response is needed for proper caching.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>It has to be kept in mind that conditions follow a short circuit
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick so that certain conditions might not be evaluated at all.</p></li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{LA-U:variable}</code> can be used for look-aheads which perform
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick an internal (URL-based) sub-request to determine the final
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick value of <em>variable</em>. This can be used to access
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick variable for rewriting which is not available at the current
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick stage, but will be set in a later phase.
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <p>For instance, to rewrite according to the
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <code>REMOTE_USER</code> variable from within the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick per-server context (<code>httpd.conf</code> file) you must
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick use <code>%{LA-U:REMOTE_USER}</code> - this
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick variable is set by the authorization phases, which come
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <em>after</em> the URL translation phase (during which mod_rewrite
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick operates).</p>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <p>On the other hand, because mod_rewrite implements
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick its per-directory context (<code>.htaccess</code> file) via
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick the Fixup phase of the API and because the authorization
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick phases come <em>before</em> this phase, you just can use
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick <code>%{REMOTE_USER}</code> in that context.</p></li>
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick <li>
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick <code>%{LA-F:variable}</code> can be used to perform an internal
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick (filename-based) sub-request, to determine the final value
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick of <em>variable</em>. Most of the time, this is the same as
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick LA-U above.</li>
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick </ol>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p><em>CondPattern</em> is the condition pattern,
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick a regular expression which is applied to the
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick current instance of the <em>TestString</em>.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>TestString</em> is first evaluated, before being matched against
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>CondPattern</em>.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p><strong>Remember:</strong> <em>CondPattern</em> is a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>perl compatible regular expression</em> with some
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick additions:</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <ol>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>You can prefix the pattern string with a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick '<code>!</code>' character (exclamation mark) to specify a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>non</strong>-matching pattern.</li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick There are some special variants of <em>CondPatterns</em>.
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick Instead of real regular expression strings you can also
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick use one of the following:
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <ul>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong>&lt;CondPattern</strong>' (lexicographically
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick precedes)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>CondPattern</em> as a plain string and
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick compares it lexicographically to <em>TestString</em>. True if
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>TestString</em> lexicographically precedes
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <em>CondPattern</em>.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <li>'<strong>&gt;CondPattern</strong>' (lexicographically
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick follows)<br />
61a4b32b1032d530e84e1131cb803f803acf7461trawick Treats the <em>CondPattern</em> as a plain string and
61a4b32b1032d530e84e1131cb803f803acf7461trawick compares it lexicographically to <em>TestString</em>. True if
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>TestString</em> lexicographically follows
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <em>CondPattern</em>.</li>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <li>'<strong>=CondPattern</strong>' (lexicographically
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick equal)<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick Treats the <em>CondPattern</em> as a plain string and
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick compares it lexicographically to <em>TestString</em>. True if
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>TestString</em> is lexicographically equal to
b4e664baba9a4be0457c31f84b3dcc4c31f2cb07kbrand <em>CondPattern</em> (the two strings are exactly
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick equal, character for character). If <em>CondPattern</em>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick is <code>""</code> (two quotation marks) this
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick compares <em>TestString</em> to the empty string.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong>-d</strong>' (is
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>d</strong>irectory)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>TestString</em> as a pathname and tests
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick whether or not it exists, and is a directory.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <li>'<strong>-f</strong>' (is regular
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <strong>f</strong>ile)<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick Treats the <em>TestString</em> as a pathname and tests
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick whether or not it exists, and is a regular file.</li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <li>'<strong>-s</strong>' (is regular file, with
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>s</strong>ize)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>TestString</em> as a pathname and tests
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick whether or not it exists, and is a regular file with size greater
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick than zero.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <li>'<strong>-l</strong>' (is symbolic
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>l</strong>ink)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>TestString</em> as a pathname and tests
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick whether or not it exists, and is a symbolic link.</li>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick permissions)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>TestString</em> as a pathname and tests
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick whether or not it exists, and has executable permissions.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick These permissions are determined according to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the underlying OS.</li>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong>-F</strong>' (is existing file, via
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Checks whether or not <em>TestString</em> is a valid file,
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick accessible via all the server's currently-configured
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick access controls for that path. This uses an internal
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest to do the check, so use it with care -
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick it can impact your server's performance!</li>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <li>'<strong>-U</strong>' (is existing URL, via
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest)<br />
e6114dbc138189372015ea6ed63bc757645922a7trawick Checks whether or not <em>TestString</em> is a valid URL,
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick accessible via all the server's currently-configured
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick access controls for that path. This uses an internal
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick subrequest to do the check, so use it with care -
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick it can impact your server's performance!</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </ul>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="note"><h3>Note:</h3>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick All of these tests can
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick also be prefixed by an exclamation mark ('!') to
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick negate their meaning.
798cfee8074b529042079c77eee6962a723350detrawick</div>
798cfee8074b529042079c77eee6962a723350detrawick </li>
798cfee8074b529042079c77eee6962a723350detrawick
798cfee8074b529042079c77eee6962a723350detrawick <li>You can also set special flags for
798cfee8074b529042079c77eee6962a723350detrawick <em>CondPattern</em> by appending
798cfee8074b529042079c77eee6962a723350detrawick <strong><code>[</code><em>flags</em><code>]</code></strong>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick as the third argument to the <code>RewriteCond</code>
798cfee8074b529042079c77eee6962a723350detrawick directive, where <em>flags</em> is a comma-separated list of any of the
798cfee8074b529042079c77eee6962a723350detrawick following flags:
798cfee8074b529042079c77eee6962a723350detrawick
798cfee8074b529042079c77eee6962a723350detrawick <ul>
798cfee8074b529042079c77eee6962a723350detrawick <li>'<strong><code>nocase|NC</code></strong>'
798cfee8074b529042079c77eee6962a723350detrawick (<strong>n</strong>o <strong>c</strong>ase)<br />
798cfee8074b529042079c77eee6962a723350detrawick This makes the test case-insensitive - differences
798cfee8074b529042079c77eee6962a723350detrawick between 'A-Z' and 'a-z' are ignored, both in the
798cfee8074b529042079c77eee6962a723350detrawick expanded <em>TestString</em> and the <em>CondPattern</em>.
798cfee8074b529042079c77eee6962a723350detrawick This flag is effective only for comparisons between
798cfee8074b529042079c77eee6962a723350detrawick <em>TestString</em> and <em>CondPattern</em>. It has no
798cfee8074b529042079c77eee6962a723350detrawick effect on filesystem and subrequest checks.</li>
798cfee8074b529042079c77eee6962a723350detrawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick '<strong><code>ornext|OR</code></strong>'
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick (<strong>or</strong> next condition)<br />
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick Use this to combine rule conditions with a local OR
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick instead of the implicit AND. Typical example:
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="example"><pre>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host1.* [OR]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host2.* [OR]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host3.*
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteRule ...some special stuff for any of these hosts...
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</pre></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Without this flag you would have to write the condition/rule
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick pair three times.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong><code>novary|NV</code></strong>'
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick (<strong>n</strong>o <strong>v</strong>ary)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick If a HTTP header is used in the condition, this flag prevents
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick this header from being added to the Vary header of the response. <br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Using this flag might break proper caching of the response if
798cfee8074b529042079c77eee6962a723350detrawick the representation of this response varies on the value of this header.
798cfee8074b529042079c77eee6962a723350detrawick So this flag should be only used if the meaning of the Vary header
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick is well understood.
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick </li>
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick </ul>
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick </li>
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick </ol>
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick <p><strong>Example:</strong></p>
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick <p>To rewrite the Homepage of a site according to the
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick ``<code>User-Agent:</code>'' header of the request, you can
9dddb8cb288d6aa75b4955285c96c8725a8a35bbtrawick use the following: </p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="example"><pre>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteRule ^/$ /homepage.max.html [L]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteRule ^/$ /homepage.min.html [L]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteRule ^/$ /homepage.std.html [L]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</pre></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>Explanation: If you use a browser which identifies itself
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick get the max homepage (which could include frames, or other special
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick features).
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick If you use the Lynx browser (which is terminal-based), then
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick you get the min homepage (which could be a version designed for
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick easy, text-only browsing).
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick If neither of these conditions apply (you use any other browser,
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick or your browser identifies itself as something non-standard), you get
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the std (standard) homepage.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<table class="directive">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</table>
5f29e9845e02a8c0a951dd81d6befa8cc76f53fbtrawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>The <code class="directive">RewriteEngine</code> directive enables or
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick disables the runtime rewriting engine. If it is set to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>off</code> this module does no runtime processing at
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick all. It does not even update the <code>SCRIPT_URx</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick environment variables.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>Use this directive to disable the module instead of
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>Note that rewrite configurations are not
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick inherited by virtual hosts. This means that you need to have a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>RewriteEngine on</code> directive for each virtual host
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick in which you wish to use rewrite rules.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p><code class="directive">RewriteMap</code> directives of the type <code>prg</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick are not started during server initialization if they're defined in a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick context that does not have <code class="directive">RewriteEngine</code> set to
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick <code>on</code></p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<table class="directive">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickprocessing</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</table>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>The <code class="directive">RewriteLog</code> directive sets the name
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick of the file to which the server logs any rewriting actions it
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick performs. If the name does not begin with a slash
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick ('<code>/</code>') then it is assumed to be relative to the
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick <em>Server Root</em>. The directive should occur only once per
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick server config.</p>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick<div class="note"> To disable the logging of
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick rewriting actions it is not recommended to set
4fb787199739239f1162e8ff35cbf42c9b452b8ftrawick <em>Filename</em> to <code>/dev/null</code>, because
4fb787199739239f1162e8ff35cbf42c9b452b8ftrawick although the rewriting engine does not then output to a
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick logfile it still creates the logfile output internally.
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick <strong>This will slow down the server with no advantage
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick to the administrator!</strong> To disable logging either
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick remove or comment out the <code class="directive">RewriteLog</code>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick directive or use <code>RewriteLogLevel 0</code>!
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick</div>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick<div class="note"><h3>Security</h3>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawickSee the <a href="/misc/security_tips.html">Apache HTTP Server Security Tips</a>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawickdocument for details on how your security could be compromised if the
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawickdirectory where logfiles are stored is writable by anyone other than
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawickthe user that starts the server.
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick</div>
4fb787199739239f1162e8ff35cbf42c9b452b8ftrawick
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick<div class="example"><h3>Example</h3><p><code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteLog "/usr/local/var/apache/logs/rewrite.log"
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</code></p></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<table class="directive">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
e6114dbc138189372015ea6ed63bc757645922a7trawickengine</td></tr>
e6114dbc138189372015ea6ed63bc757645922a7trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
e6114dbc138189372015ea6ed63bc757645922a7trawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick</table>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>The <code class="directive">RewriteLogLevel</code> directive sets the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick verbosity level of the rewriting logfile. The default level 0
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick means no logging, while 9 or more means that practically all
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick actions are logged.</p>
e6114dbc138189372015ea6ed63bc757645922a7trawick
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick <p>To disable the logging of rewriting actions simply set
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>Level</em> to 0. This disables all rewrite action
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick logs.</p>
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick<div class="note"> Using a high value for
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <em>Level</em> will slow down your Apache HTTP Server
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick dramatically! Use the rewriting logfile at a
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick <em>Level</em> greater than 2 only for debugging!
e5819d621124ccc8ee3b7f1854c2d55ffaf91d32trawick</div>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<div class="example"><h3>Example</h3><p><code>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawickRewriteLogLevel 3
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick</code></p></div>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick</div>
1f5a6b18eb1d06210b03a7c8ea7a07506f5949ddtrawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<table class="directive">
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick</code></td></tr>
1f5a6b18eb1d06210b03a7c8ea7a07506f5949ddtrawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawickApache HTTP Server 2.0.41 and later</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</table>
e6114dbc138189372015ea6ed63bc757645922a7trawick <p>The <code class="directive">RewriteMap</code> directive defines a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>Rewriting Map</em> which can be used inside rule
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick substitution strings by the mapping-functions to
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick insert/substitute fields through a key lookup. The source of
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick this lookup can be of various types.</p>
e6114dbc138189372015ea6ed63bc757645922a7trawick
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick the name of the map and will be used to specify a
e6114dbc138189372015ea6ed63bc757645922a7trawick mapping-function for the substitution strings of a rewriting
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick rule via one of the following constructs:</p>
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p class="indent">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong><code>${</code> <em>MapName</em> <code>:</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>LookupKey</em> <code>}</code><br />
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <code>${</code> <em>MapName</em> <code>:</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <code>}</code></strong>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick </p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <p>When such a construct occurs, the map <em>MapName</em> is
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick consulted and the key <em>LookupKey</em> is looked-up. If the
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick key is found, the map-function construct is substituted by
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <em>SubstValue</em>. If the key is not found then it is
5a2741099e61f454d3071092ae7e606418e5809atrawick substituted by <em>DefaultValue</em> or by the empty string
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick if no <em>DefaultValue</em> was specified.</p>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <p>For example, you might define a
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <code class="directive">RewriteMap</code> as:</p>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <div class="example"><p><code>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick RewriteMap examplemap txt:/path/to/file/map.txt
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick </code></p></div>
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>You would then be able to use this map in a
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick <code class="directive">RewriteRule</code> as follows:</p>
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick <div class="example"><p><code>
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick RewriteRule ^/ex/(.*) ${examplemap:$1}
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick </code></p></div>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <p>The following combinations for <em>MapType</em> and
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>MapSource</em> can be used:</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <ul>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>Standard Plain Text</strong><br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick MapType: <code>txt</code>, MapSource: Unix filesystem
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick path to valid regular file
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>This is the standard rewriting map feature where the
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <em>MapSource</em> is a plain ASCII file containing
633bb5999839dd4433603525a2b76dc3be6df8f4trawick either blank lines, comment lines (starting with a '#'
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick character) or pairs like the following - one per
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick line.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p class="indent">
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong><em>MatchingKey</em>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>SubstValue</em></strong>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
5a2741099e61f454d3071092ae7e606418e5809atrawick<div class="example"><h3>Example</h3><pre>
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick##
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick## map.txt -- rewriting map
bc2c3a74fda3d3684ecb4a8a94ca03e5604ef670trawick##
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawickRalf.S.Engelschall rse # Bastard Operator From Hell
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawickMr.Joe.Average joe # Mr. Average
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick</pre></div>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="example"><p><code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteMap real-to-user txt:/path/to/file/map.txt
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick</code></p></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <li>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <strong>Randomized Plain Text</strong><br />
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick MapType: <code>rnd</code>, MapSource: Unix filesystem
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick path to valid regular file
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <p>This is identical to the Standard Plain Text variant
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick above but with a special post-processing feature: After
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick looking up a value it is parsed according to contained
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick ``<code>|</code>'' characters which have the meaning of
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick ``or''. In other words they indicate a set of
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick alternatives from which the actual returned value is
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick chosen randomly. For example, you might use the following map
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick file and directives to provide a random load balancing between
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick several back-end server, via a reverse-proxy. Images are sent
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick to one of the servers in the 'static' pool, while everything
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick else is sent to one of the 'dynamic' pool.</p>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <p>Example:</p>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick<div class="example"><h3>Rewrite map file</h3><pre>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick##
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick## map.txt -- rewriting map
5a2741099e61f454d3071092ae7e606418e5809atrawick##
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawickstatic www1|www2|www3|www4
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawickdynamic www5|www6
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick</pre></div>
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick<div class="example"><h3>Configuration directives</h3><p><code>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawickRewriteMap servers rnd:/path/to/file/map.txt<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<br />
5a2741099e61f454d3071092ae7e606418e5809atrawickRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick[NC,P,L]<br />
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawickRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick</code></p></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </li>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <li>
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick <strong>Hash File</strong><br /> MapType:
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick path to valid regular file
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>Here the source is a binary format DBM file containing
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the same contents as a <em>Plain Text</em> format file, but
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick in a special representation which is optimized for really
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick db depending on <a href="/install.html#dbm">compile-time
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick settings</a>. If the <em>type</em> is omitted, the
39d69ffeb80a2db1b3ffeed705f0652b1e77fe49trawick compile-time default will be chosen.</p>
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<div class="example"><p><code>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick$ httxt2dbm -i mapfile.txt -o mapfile.map
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick</code></p></div>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick </li>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <li>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <strong>Internal Function</strong><br />
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick MapType: <code>int</code>, MapSource: Internal Apache httpd
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick function
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>Here, the source is an internal Apache httpd function.
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick Currently you cannot create your own, but the following
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick functions already exist:</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <ul>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <li><strong>toupper</strong>:<br />
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick Converts the key to all upper case.</li>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <li><strong>tolower</strong>:<br />
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick Converts the key to all lower case.</li>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <li><strong>escape</strong>:<br />
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick Translates special characters in the key to
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick hex-encodings.</li>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <li><strong>unescape</strong>:<br />
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick Translates hex-encodings in the key back to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick special characters.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </ul>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick </li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>External Rewriting Program</strong><br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick MapType: <code>prg</code>, MapSource: Unix filesystem
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick path to valid regular file
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <p>Here the source is a program, not a map file. To
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick create it you can use a language of your choice, but
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick the result has to be an executable program (either
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick object-code or a script with the magic cookie trick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick '<code>#!/path/to/interpreter</code>' as the first
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick line).</p>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <p>This program is started once, when the Apache httpd server
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick is started, and then communicates with the rewriting engine
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick via its <code>stdin</code> and <code>stdout</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick file-handles. For each map-function lookup it will
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick receive the key to lookup as a newline-terminated string
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick on <code>stdin</code>. It then has to give back the
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick looked-up value as a newline-terminated string on
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick <code>stdout</code> or the four-character string
4e12fead2bfdf613e0e2149f9f853edce6eab1fctrawick ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick is no corresponding value for the given key).</p>
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <p>This feature utilizes the <code>rewrite-map</code> mutex,
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick which is required for reliable communication with the program.
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick The mutex mechanism and lock file can be configured with the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code class="directive"><a href="/mod/core.html#mutex">Mutex</a></code> directive.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>External rewriting programs are not started if they're defined in a
a8002cb6eb5309086e06721eb2cdc20b891840fftrawick context that does not have <code class="directive">RewriteEngine</code> set to
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <code>on</code></p>.
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>A trivial program which will implement a 1:1 map (<em>i.e.</em>,
a8002cb6eb5309086e06721eb2cdc20b891840fftrawick key == value) could be:</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<div class="example"><pre>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick#!/usr/bin/perl
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick$| = 1;
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawickwhile (&lt;STDIN&gt;) {
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick # ...put here any transformations or lookups...
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick print $_;
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick}
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick</pre></div>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>But be very careful:</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <ol>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <li>``<em>Keep it simple, stupid</em>'' (KISS).
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick If this program hangs, it will cause Apache httpd to hang
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick when trying to use the relevant rewrite rule.</li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <li>A common mistake is to use buffered I/O on
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick <code>stdout</code>. Avoid this, as it will cause a deadloop!
0ce6a6bda16e6c66ee68cc9784db36cc1bd558a7trawick ``<code>$|=1</code>'' is used above, to prevent this.</li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick </ol>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick </li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p><strong>SQL Query</strong><br />
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick MapType: <code>dbd</code> or <code>fastdbd</code>,
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick MapSource: An SQL SELECT statement that takes a single
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick argument and returns a single value.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>This uses <code class="module"><a href="/mod/mod_dbd.html">mod_dbd</a></code> to implement a rewritemap
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick by lookup in an SQL database. There are two forms:
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick <code>fastdbd</code> caches database lookups internally,
bbd9d609b3e1f45b4a5beda3ef5e8a589b3657b4trawick <code>dbd</code> doesn't. So <code>dbd</code> incurs a
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick performance penalty but responds immediately if the database
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick contents are updated, while <code>fastdbd</code> is more
e6114dbc138189372015ea6ed63bc757645922a7trawick efficient but won't re-read database contents until server
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick restart.</p>
e6114dbc138189372015ea6ed63bc757645922a7trawick <p>If a query returns more than one row, a random row from
e6114dbc138189372015ea6ed63bc757645922a7trawick the result set is used.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<div class="example"><h3>Example</h3><p><code>
e6114dbc138189372015ea6ed63bc757645922a7trawick
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawickRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
e6114dbc138189372015ea6ed63bc757645922a7trawick</code></p></div>
e6114dbc138189372015ea6ed63bc757645922a7trawick </li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick </ul>
e6114dbc138189372015ea6ed63bc757645922a7trawick <p>The <code class="directive">RewriteMap</code> directive can occur more than
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick once. For each mapping-function use one
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code class="directive">RewriteMap</code> directive to declare its rewriting
mapfile. While you cannot <strong>declare</strong> a map in
per-directory context it is of course possible to
<strong>use</strong> this map in per-directory context. </p>
<div class="note"><h3>Note</h3> For plain text and DBM format files the
looked-up keys are cached in-core until the <code>mtime</code> of the
mapfile changes or the server does a restart. This way you can have
map-functions in rules which are used for <strong>every</strong>
request. This is no problem, because the external lookup only happens
once!
</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="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></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>
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
later</td></tr>
</table>
<p>The <code class="directive">RewriteOptions</code> directive sets some
special options for the current per-server or per-directory
configuration. The <em>Option</em> string can currently
only be one of the following:</p>
<dl>
<dt><code>inherit</code></dt>
<dd>This forces the current configuration to inherit the
configuration of the parent. In per-virtual-server context,
this means that the maps, conditions and rules of the main
server are inherited. In per-directory context this means
that conditions and rules of the parent directory's
<code>.htaccess</code> configuration or
<code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code>
sections are inherited. The inherited rules are virtually copied
to the section where this directive is being used. If used in
combination with local rules, the inherited rules are copied behind
the local rules. The position of this directive - below or above
of local rules - has no influence on this behavior. If local
rules forced the rewriting to stop, the inherited rules won't
be processed.</dd>
</dl>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteRule
<em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</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">RewriteRule</code> directive is the real
rewriting workhorse. The directive can occur more than once,
with each instance defining a single rewrite rule. The
order in which these rules are defined is important - this is the order
in which they will be applied at run-time.</p>
<p><a id="patterns" name="patterns"><em>Pattern</em></a> is
a perl compatible <a id="regexp" name="regexp">regular
expression</a>. On the first RewriteRule it is applied to the (%-encoded)
<a href="/directive-dict.html#Syntax">URL-path</a> of the request;
subsequent patterns are applied to the output of the last matched
RewriteRule.</p>
<div class="note"><h3>What is matched?</h3>
<p>The <em>Pattern</em> will initially be matched against the part of the
URL after the hostname and port, and before the query string.</p>
<p>When the RewriteRule appears in per-directory (htaccess) context, the
<em>Pattern</em> is matched against what remains of the URL after removing
the prefix that lead Apache httpd to the current rules (see the
<code class="directive"><a href="#rewritebase">RewriteBase</a></code>). The removed prefix
always ends with a slash, meaning the matching occurs against a string which
never has a leading slash. A <em>Pattern</em> with <code>^/</code> never
matches in per-directory context.</p>
<p>If you wish to match against the hostname, port, or query string, use a
<code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
<code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
<code>%{QUERY_STRING}</code> variables respectively. If you wish to
match against the full URL-path in a per-directory (htaccess) RewriteRule,
use the <code>%{REQUEST_URI}</code> variable.</p>
</div>
<p>For some hints on <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
expressions</a>, see
the <a href="/rewrite/intro.html#regex">mod_rewrite
Introduction</a>.</p>
<p>In mod_rewrite, the NOT character
('<code>!</code>') is also available as a possible pattern
prefix. This enables you to negate a pattern; to say, for instance:
``<em>if the current URL does <strong>NOT</strong> match this
pattern</em>''. This can be used for exceptional cases, where
it is easier to match the negative pattern, or as a last
default rule.</p>
<div class="note"><h3>Note</h3>
When using the NOT character to negate a pattern, you cannot include
grouped wildcard parts in that pattern. This is because, when the
pattern does NOT match (ie, the negation matches), there are no
contents for the groups. Thus, if negated patterns are used, you
cannot use <code>$N</code> in the substitution string!
</div>
<p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
rewrite rule is the string that replaces the original URL-path that
was matched by <em>Pattern</em>. The <em>Substitution</em> may
be a:</p>
<dl>
<dt>file-system path</dt>
<dd>Designates the location on the file-system of the resource
to be delivered to the client.</dd>
<dt>URL-path</dt>
<dd>A <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>-relative path to the
resource to be served. Note that <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
tries to guess whether you have specified a file-system path
or a URL-path by checking to see if the first segment of the
path exists at the root of the file-system. For example, if
you specify a <em>Substitution</em> string of
<code>/www/file.html</code>, then this will be treated as a
URL-path <em>unless</em> a directory named <code>www</code>
exists at the root or your file-system, in which case it will
be treated as a file-system path. If you wish other
URL-mapping directives (such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
resulting URL-path, use the <code>[PT]</code> flag as
described below.</dd>
<dt>Absolute URL</dt>
<dd>If an absolute URL is specified,
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
hostname matches the current host. If it does, the scheme and
hostname are stripped out and the resulting path is treated as
a URL-path. Otherwise, an external redirect is performed for
the given URL. To force an external redirect back to the
current host, see the <code>[R]</code> flag below.</dd>
<dt><code>-</code> (dash)</dt>
<dd>A dash indicates that no substitution should be performed
(the existing path is passed through untouched). This is used
when a flag (see below) needs to be applied without changing
the path.</dd>
</dl>
<p>In addition to plain text, the <em>Substition</em> string can include</p>
<ol>
<li>back-references (<code>$N</code>) to the RewriteRule
pattern</li>
<li>back-references (<code>%N</code>) to the last matched
RewriteCond pattern</li>
<li>server-variables as in rule condition test-strings
(<code>%{VARNAME}</code>)</li>
<li><a href="#mapfunc">mapping-function</a> calls
(<code>${mapname:key|default}</code>)</li>
</ol>
<p>Back-references are identifiers of the form
<code>$</code><strong>N</strong>
(<strong>N</strong>=0..9), which will be replaced
by the contents of the <strong>N</strong>th group of the
matched <em>Pattern</em>. The server-variables are the same
as for the <em>TestString</em> of a <code>RewriteCond</code>
directive. The mapping-functions come from the
<code>RewriteMap</code> directive and are explained there.
These three types of variables are expanded in the order above.</p>
<p>As already mentioned, all rewrite rules are
applied to the <em>Substitution</em> (in the order in which
they are defined
in the config file). The URL is <strong>completely
replaced</strong> by the <em>Substitution</em> and the
rewriting process continues until all rules have been applied,
or it is explicitly terminated by a
<code><strong>L</strong></code> flag.</p>
<div class="note"><h3>Modifying the Query String</h3>
<p>By default, the query string is passed through unchanged. You
can, however, create URLs in the substitution string containing
a query string part. Simply use a question mark inside the
substitution string to indicate that the following text should
be re-injected into the query string. When you want to erase an
existing query string, end the substitution string with just a
question mark. To combine new and old query strings, use the
<code>[QSA]</code> flag.</p>
</div>
<p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
appending <strong><code>[</code><em>flags</em><code>]</code></strong>
as the third argument to the <code>RewriteRule</code>
directive. <em>Flags</em> is a comma-separated list, surround by square
brackets, of any of the flags in the following table. More
details, and examples, for each flag, are available in the <a href="/rewrite/flags.html">Rewrite Flags document</a>.</p>
<table>
<tr><th>Flag and syntax</th>
<th>Function</th>
</tr>
<tr>
<td>B</td>
<td>Escape non-alphanumeric characters <em>before</em> applying
the transformation. <em><a href="/rewrite/flags.html#flag_b">details ...</a></em></td>
</tr>
<tr>
<td>chain|C</td>
<td>Rule is chained to the following rule. If the rule fails,
the rule(s) chained to it will be skipped. <em><a href="/rewrite/flags.html#flag_c">details ...</a></em></td>
</tr>
<tr>
<td>cookie|CO=<em>NAME</em>:<em>VAL</em></td>
<td>Sets a cookie in the client browser. Full syntax is:
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>
</td>
</tr>
<tr>
<td>discardpathinfo|DPI</td>
<td>Causes the PATH_INFO portion of the rewritten URI to be
discarded. <em><a href="/rewrite/flags.html#flag_dpi">details
...</a></em></td>
</tr>
<tr>
<td>env|E=<em>VAR</em>:<em>VAL</em></td>
<td>Causes an environment variable <em>VAR</em> to be set to the
value <em>VAL</em>. <em><a href="/rewrite/flags.html#flag_e">details ...</a></em></td>
</tr>
<tr>
<td>forbidden|F</td>
<td>Returns a 403 FORBIDDEN response to the client browser.
<em><a href="/rewrite/flags.html#flag_f">details ...</a></em></td>
</tr>
<tr>
<td>gone|G</td>
<td>Returns a 410 GONE response to the client browser. <em><a href="/rewrite/flags.html#flag_g">details ...</a></em></td>
</tr>
<tr>
<td>Handler|H=<em>Content-handler</em></td>
<td>Causes the resulting URI to be sent to the specified
<em>Content-handler</em> for processing. <em><a href="/rewrite/flags.html#flag_h">details ...</a></em></td>
</tr>
<tr>
<td>last|L</td>
<td>Stop the rewriting process immediately and don't apply any
more rules. Especially note caveats for per-directory and
.htaccess context. <em><a href="/rewrite/flags.html#flag_l">details ...</a></em></td>
</tr>
<tr>
<td>next|N</td>
<td>Re-run the rewriting process, starting again with the first
rule, using the result of the ruleset so far as a starting
point. <em><a href="/rewrite/flags.html#flag_n">details
...</a></em></td>
</tr>
<tr>
<td>nocase|NC</td>
<td>Makes the pattern pattern comparison case-insensitive.
<em><a href="/rewrite/flags.html#flag_nc">details ...</a></em></td>
</tr>
<tr>
<td>noescape|NE</td>
<td>Prevent mod_rewrite from applying hexcode escaping of
special characters in the result of the rewrite. <em><a href="/rewrite/flags.html#flag_ne">details ...</a></em></td>
</tr>
<tr>
<td>nosubreq|NS</td>
<td>Causes a rule to be skipped if the current request is an
internal sub-request. <em><a href="/rewrite/flags.html#flag_ns">details ...</a></em></td>
</tr>
<tr>
<td>proxy|P</td>
<td>Force the substitution URL to be internally sent as a proxy
request. <em><a href="/rewrite/flags.html#flag_p">details
...</a></em></td>
</tr>
<tr>
<td>passthrough|PT</td>
<td>Forces the resulting URI to be passed back to the URL
mapping engine for processing of other URI-to-filename
translators, such as <code>Alias</code> or
<code>Redirect</code>. <em><a href="/rewrite/flags.html#flag_pt">details ...</a></em></td>
</tr>
<tr>
<td>qsappend|QSA</td>
<td>Appends any query string created in the rewrite target to
any query string that was in the original request URL. <em><a href="/rewrite/flags.html#flag_qsa">details ...</a></em></td>
</tr>
<tr>
<td>qsdiscard|QSD</td>
<td>Discard any query string attached to the incoming URI.
<em><a href="/rewrite/flags.html#flag_qsd">details
...</a></em></td>
</tr>
<tr>
<td>redirect|R[=<em>code</em>]</td>
<td>Forces an external redirect, optionally with the specified
HTTP status code. <em><a href="/rewrite/flags.html#flag_r">details ...</a></em>
</td>
</tr>
<tr>
<td>skip|S=<em>num</em></td>
<td>Tells the rewriting engine to skip the next <em>num</em>
rules if the current rule matches. <em><a href="/rewrite/flags.html#flag_s">details ...</a></em></td>
</tr>
<tr>
<td>tyle|T=<em>MIME-type</em></td>
<td>Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file
to be the specified type. <em><a href="/rewrite/flags.html#flag_t">details ...</a></em></td>
</tr>
</table>
<div class="note"><h3>Home directory expansion</h3>
<p> When the substitution string begins with a string
resembling "/~user" (via explicit text or backreferences), mod_rewrite performs
home directory expansion independent of the presence or configuration
of <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>.</p>
<p> This expansion does not occur when the <em>PT</em>
flag is used on the <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
directive.</p>
</div>
<div class="note"><h3>Per-directory Rewrites</h3>
<p>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files. To enable the
rewrite engine for these files you need to set
"<code>RewriteEngine On</code>" <strong>and</strong>
"<code>Options FollowSymLinks</code>" must be enabled. If your
administrator has disabled override of <code>FollowSymLinks</code> for
a user's directory, then you cannot use the rewrite engine. This
restriction is required for security reasons.</p>
<p>When using the rewrite engine in <code>.htaccess</code> files the
per-directory prefix (which always is the same for a specific
directory) is automatically <em>removed</em> for the pattern matching
and automatically <em>added</em> after the substitution has been
done. This feature is essential for many sorts of rewriting; without
this, you would always have to match the parent directory, which is
not always possible. There is one exception: If a substitution string
starts with <code>http://</code>, then the directory prefix will
<strong>not</strong> be added, and an external redirect (or proxy
throughput, if using flag <strong>P</strong>) is forced. See the
<code class="directive"><a href="#rewritebase">RewriteBase</a></code> directive for
more information.</p>
<p>The rewrite engine may also be used in <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> sections with the same
prefix-matching rules as would be applied to <code>.htaccess</code>
files. It is usually simpler, however, to avoid the prefix substitution
complication by putting the rewrite rules in the main server or
virtual host context, rather than in a <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> section.</p>
<p>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
should never be necessary and is unsupported.</p>
</div>
<p>Here are all possible substitution combinations and their
meanings:</p>
<p><strong>Inside per-server configuration
(<code>httpd.conf</code>)<br />
for request ``<code>GET
/somepath/pathinfo</code>'':</strong><br />
</p>
<div class="note"><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 invalid, not supported
^/somepath(.*) otherpath$1 [R] invalid, not supported
^/somepath(.*) otherpath$1 [P] invalid, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></div>
<p><strong>Inside per-directory configuration for
<code>/somepath</code><br />
(<code>/physical/path/to/somepath/.htacccess</code>, with
<code>RewriteBase /somepath</code>)<br />
for request ``<code>GET
/somepath/localpath/pathinfo</code>'':</strong><br />
</p>
<div class="note"><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
via external redirection
^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></div>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2010 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>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>