mod_rewrite.html.en revision e00def5e805da9a73b72ad25dac664f0c8c36c2e
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<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<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<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Modules</a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div id="preamble"><h1>Apache Module mod_rewrite</h1>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a></p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick<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>
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr>
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 1.3 and later</td></tr></table>
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick <p>This module uses a rule-based rewriting engine (based on a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick regular-expression parser) to rewrite requested URLs on the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick fly. It supports an unlimited number of rules and an
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick unlimited number of attached rule conditions for each rule, to
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick provide a really flexible and powerful URL manipulation
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick mechanism. The URL manipulations can depend on various tests,
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick of server variables, environment variables, HTTP
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick headers, or time stamps. Even external database lookups in
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick various formats can be used to achieve highly granular URL
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick matching.</p>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick <p>This module operates on the full URLs (including the
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick path-info part) both in per-server context
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick (<code>.htaccess</code>) and can generate query-string
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick parts on result. The rewritten result can lead to internal
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick sub-processing, external request redirection or even to an
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick internal proxy throughput.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>Further details, discussion, and examples, are provided in the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<div id="quickview"><h3 class="directives">Directives</h3>
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>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritelock">RewriteLock</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick<li><img alt="" src="/images/down.gif" /> <a href="#quoting">Quoting Special Characters</a></li>
798cfee8074b529042079c77eee6962a723350detrawick<li><img alt="" src="/images/down.gif" /> <a href="#EnvVar">Environment Variables</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#vhosts">Rewriting in Virtual Hosts</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<li><img alt="" src="/images/down.gif" /> <a href="#Solutions">Practical Solutions</a></li>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick<h2><a name="quoting" id="quoting">Quoting Special Characters</a></h2>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>As of Apache 1.3.20, special characters in
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <em>TestString</em> and <em>Substitution</em> strings can be
61a4b32b1032d530e84e1131cb803f803acf7461trawick escaped (that is, treated as normal characters without their
61a4b32b1032d530e84e1131cb803f803acf7461trawick usual special meaning) by prefixing them with a slash ('\')
61a4b32b1032d530e84e1131cb803f803acf7461trawick character. In other words, you can include an actual
61a4b32b1032d530e84e1131cb803f803acf7461trawick dollar-sign character in a <em>Substitution</em> string by
61a4b32b1032d530e84e1131cb803f803acf7461trawick using '<code>\$</code>'; this keeps mod_rewrite from trying
61a4b32b1032d530e84e1131cb803f803acf7461trawick to treat it as a backreference.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<h2><a name="EnvVar" id="EnvVar">Environment Variables</a></h2>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>This module keeps track of two additional (non-standard)
61a4b32b1032d530e84e1131cb803f803acf7461trawick CGI/SSI environment variables named <code>SCRIPT_URL</code>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <em>logical</em> Web-view to the current resource, while the
61a4b32b1032d530e84e1131cb803f803acf7461trawick standard CGI/SSI variables <code>SCRIPT_NAME</code> and
61a4b32b1032d530e84e1131cb803f803acf7461trawick <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
61a4b32b1032d530e84e1131cb803f803acf7461trawick System-view. </p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>Notice: These variables hold the URI/URL <em>as they were
61a4b32b1032d530e84e1131cb803f803acf7461trawick initially requested</em>, that is, <em>before</em> any
61a4b32b1032d530e84e1131cb803f803acf7461trawick rewriting. This is important to note because the rewriting process is
61a4b32b1032d530e84e1131cb803f803acf7461trawick primarily used to rewrite logical URLs to physical
61a4b32b1032d530e84e1131cb803f803acf7461trawick pathnames.</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawickSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
61a4b32b1032d530e84e1131cb803f803acf7461trawick</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<h2><a name="vhosts" id="vhosts">Rewriting in Virtual Hosts</a></h2>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> configuration
61a4b32b1032d530e84e1131cb803f803acf7461trawick settings from the main server context are not inherited by
61a4b32b1032d530e84e1131cb803f803acf7461trawick virtual hosts. To make the main server settings apply to virtual
61a4b32b1032d530e84e1131cb803f803acf7461trawick hosts, you must place the following directives in each <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> section:</p>
61a4b32b1032d530e84e1131cb803f803acf7461trawick RewriteEngine On<br />
61a4b32b1032d530e84e1131cb803f803acf7461trawick RewriteOptions Inherit
61a4b32b1032d530e84e1131cb803f803acf7461trawick</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<h2><a name="Solutions" id="Solutions">Practical Solutions</a></h2>
61a4b32b1032d530e84e1131cb803f803acf7461trawick <p>For numerous examples of common, and not-so-common, uses for
61a4b32b1032d530e84e1131cb803f803acf7461trawick mod_rewrite, see the <a href="/rewrite/rewrite_guide.html">Rewrite
61a4b32b1032d530e84e1131cb803f803acf7461trawick Guide</a>, and the <a href="/rewrite/rewrite_guide_advanced.html">Advanced Rewrite
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>See usage for information.</code></td></tr>
61a4b32b1032d530e84e1131cb803f803acf7461trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>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>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>The <code class="directive">RewriteBase</code> directive explicitly
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick sets the base URL for per-directory rewrites. As you will see
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick below, <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick can be used in per-directory config files
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick (<code>.htaccess</code>). In such a case, it will act locally,
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick stripping the local directory prefix before processing, and applying
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick rewrite rules only to the remainder. When processing is complete, the
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick prefix is automatically added back to the
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick path. The default setting is; <code class="directive">RewriteBase</code> <em>physical-directory-path</em></p>
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick <p>When a substitution occurs for a new URL, this module has
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick to re-inject the URL into the server processing. To be able
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick to do this it needs to know what the corresponding URL-prefix
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick or URL-base is. By default this prefix is the corresponding
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick filepath itself. <strong>However, for most websites, URLs are NOT
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick directly related to physical filename paths, so this
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick assumption will often be wrong!</strong> Therefore, you can
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick use the <code>RewriteBase</code> directive to specify the
cf30286e95bd9b293bb4e3d5e4b89ed9d51d7a3ftrawick correct URL-prefix.</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<div class="note"> If your webserver's URLs are <strong>not</strong> directly
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickrelated to physical file paths, you will need to use
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<code class="directive">RewriteBase</code> in every <code>.htaccess</code>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickfile where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p> For example, assume the following per-directory config file:</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick# /abc/def/.htaccess -- per-dir config file for directory /abc/def
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick# has a 'Alias /xyz /abc/def' directive <em>e.g.</em>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickRewriteEngine On
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick# let the server know that we were reached via /xyz and not
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickRewriteBase /xyz
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick# now the rewriting rules
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickRewriteRule ^oldstuff\.html$ newstuff.html
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>In the above example, a request to
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>/xyz/oldstuff.html</code> gets correctly rewritten to
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the physical file <code>/abc/def/newstuff.html</code>.</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<p>The following list gives detailed information about
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the internal processing steps:</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawickInternal Processing:
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias)
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule)
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase)
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias)
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p>This seems very complicated, but is in fact
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick correct Apache internal processing. Because the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick per-directory rewriting comes late in the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick process, the rewritten request
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick has to be re-injected into the Apache kernel.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick This is not the serious overhead it may seem to be -
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick this re-injection is completely internal to the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick Apache server (and the same procedure is used by
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick many other operations within Apache).</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <em>TestString</em> <em>CondPattern</em></code></td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick<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 <p>The <code class="directive">RewriteCond</code> directive defines a
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick rule condition. One or more <code class="directive">RewriteCond</code>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick directive. The following rule is then only used if both
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <p><em>TestString</em> is a string which can contain the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick following expanded constructs in addition to plain text:</p>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <strong>RewriteRule backreferences</strong>: These are
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick backreferences of the form <strong><code>$N</code></strong>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick (0 <= N <= 9), which provide access to the grouped
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick parts (in parentheses) of the pattern, from the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>RewriteRule</code> which is subject to the current
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <strong>RewriteCond backreferences</strong>: These are
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick backreferences of the form <strong><code>%N</code></strong>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick (1 <= N <= 9), which provide access to the grouped
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick parts (again, in parentheses) of the pattern, from the last matched
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick of conditions.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick expansions of the form <strong><code>${mapname:key|default}</code></strong>.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick RewriteMap</a> for more details.
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <strong>Server-Variables</strong>: These are variables of
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick where <em>NAME_OF_VARIABLE</em> can be a string taken
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick from the following list:
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <th>HTTP headers:</th> <th>connection & request:</th> <th />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick HTTP_USER_AGENT<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick HTTP_REFERER<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick HTTP_COOKIE<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick HTTP_FORWARDED<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick HTTP_HOST<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick HTTP_PROXY_CONNECTION<br />
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick HTTP_ACCEPT<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick REMOTE_ADDR<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick REMOTE_HOST<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick REMOTE_PORT<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick REMOTE_USER<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick REMOTE_IDENT<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick REQUEST_METHOD<br />
8b69a6447203b4cbd4c063010092dbe931503644trawick SCRIPT_FILENAME<br />
8b69a6447203b4cbd4c063010092dbe931503644trawick PATH_INFO<br />
8b69a6447203b4cbd4c063010092dbe931503644trawick QUERY_STRING<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick AUTH_TYPE<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick DOCUMENT_ROOT<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_ADMIN<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_NAME<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_ADDR<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_PORT<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_PROTOCOL<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick SERVER_SOFTWARE<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick TIME_YEAR<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick TIME_MON<br />
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick TIME_DAY<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick TIME_HOUR<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick TIME_MIN<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick TIME_SEC<br />
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick TIME_WDAY<br />
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick API_VERSION<br />
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick THE_REQUEST<br />
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick REQUEST_URI<br />
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick REQUEST_FILENAME<br />
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick IS_SUBREQ<br />
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick HTTPS<br />
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick <p>These variables all
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick correspond to the similarly named HTTP
a7b9ea00b96407cc3c1f3660162b3cb4918af396trawick MIME-headers, C variables of the Apache server or
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Most are documented elsewhere in the Manual or in
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the CGI specification. Those that are special to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick mod_rewrite include those below.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <dd>Will contain the text "true" if the request
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick currently being processed is a sub-request,
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick "false" otherwise. Sub-requests may be generated
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick by modules that need to resolve additional files
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick or URIs in order to complete their tasks.</dd>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <dd>This is the version of the Apache module API
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick (the internal interface between server and
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick module) in the current httpd build, as defined in
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick corresponds to the version of Apache in use (in
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the release version of Apache 1.3.14, for
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick instance, it is 19990320:10), but is mainly of
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick interest to module authors.</dd>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <dd>The full HTTP request line sent by the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick include any additional headers sent by the
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick browser.</dd>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <dd>The resource requested in the HTTP request
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick line. (In the example above, this would be
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <dd>The full local filesystem path to the file or
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick script matching the request.</dd>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <dd>Will contain the text "on" if the connection is
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick can be safely used regardless of whether or not
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded).</dd>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick contain the same value - the value of the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>request_rec</code> structure of the Apache server.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick The first name is the commonly known CGI variable name
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick while the second is the appropriate counterpart of
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick REQUEST_URI (which contains the value of the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>uri</code> field of <code>request_rec</code>).</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{ENV:variable}</code>, where <em>variable</em> can be
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick any environment variable, is also available.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick This is looked-up via internal
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick Apache structures and (if not found there) via
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>getenv()</code> from the Apache server process.</li>
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick <code>%{SSL:variable}</code>, where <em>variable</em> is the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick name of an <a href="mod_ssl.html#envvars">SSL environment
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick variable</a>, can be used whether or not
e6114dbc138189372015ea6ed63bc757645922a7trawick <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>%{HTTP:header}</code>, where <em>header</em> can be
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick any HTTP MIME-header name, can always be used to obtain the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick value of a header sent in the HTTP request.
798cfee8074b529042079c77eee6962a723350detrawick the value of the HTTP header
798cfee8074b529042079c77eee6962a723350detrawick <p>If a HTTP header is used in a condition this header is added to
798cfee8074b529042079c77eee6962a723350detrawick the Vary header of the response in case the condition evaluates to
798cfee8074b529042079c77eee6962a723350detrawick to true for the request. It is <strong>not</strong> added if the
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick condition evaluates to false for the request. Adding the HTTP header
798cfee8074b529042079c77eee6962a723350detrawick to the Vary header of the response is needed for proper caching.</p>
798cfee8074b529042079c77eee6962a723350detrawick <p>It has to be kept in mind that conditions follow a short circuit
798cfee8074b529042079c77eee6962a723350detrawick logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
798cfee8074b529042079c77eee6962a723350detrawick so that certain conditions might not be evaluated at all.</p></li>
798cfee8074b529042079c77eee6962a723350detrawick <code>%{LA-U:variable}</code> can be used for look-aheads which perform
798cfee8074b529042079c77eee6962a723350detrawick an internal (URL-based) sub-request to determine the final
798cfee8074b529042079c77eee6962a723350detrawick value of <em>variable</em>. This can be used to access
798cfee8074b529042079c77eee6962a723350detrawick variable for rewriting which is not available at the current
798cfee8074b529042079c77eee6962a723350detrawick stage, but will be set in a later phase.
798cfee8074b529042079c77eee6962a723350detrawick <p>For instance, to rewrite according to the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick per-server context (<code>httpd.conf</code> file) you must
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick variable is set by the authorization phases, which come
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>after</em> the URL translation phase (during which mod_rewrite
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick operates).</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p>On the other hand, because mod_rewrite implements
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick its per-directory context (<code>.htaccess</code> file) via
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the Fixup phase of the API and because the authorization
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick phases come <em>before</em> this phase, you just can use
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{REMOTE_USER}</code> in that context.</p></li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <code>%{LA-F:variable}</code> can be used to perform an internal
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick (filename-based) sub-request, to determine the final value
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick of <em>variable</em>. Most of the time, this is the same as
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick LA-U above.</li>
798cfee8074b529042079c77eee6962a723350detrawick a regular expression which is applied to the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>TestString</em> is first evaluated, before being matched against
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <p><strong>Remember:</strong> <em>CondPattern</em> is a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>perl compatible regular expression</em> with some
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick additions:</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>You can prefix the pattern string with a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick '<code>!</code>' character (exclamation mark) to specify a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick There are some special variants of <em>CondPatterns</em>.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Instead of real regular expression strings you can also
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick use one of the following:
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong><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 <li>'<strong>>CondPattern</strong>' (lexicographically
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick follows)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>CondPattern</em> as a plain string and
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick compares it lexicographically to <em>TestString</em>. True if
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <li>'<strong>=CondPattern</strong>' (lexicographically
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick equal)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>CondPattern</em> as a plain string and
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick compares it lexicographically to <em>TestString</em>. True if
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick equal, character for character). If <em>CondPattern</em>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick compares <em>TestString</em> to the empty string.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Treats the <em>TestString</em> as a pathname and tests
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick whether or not it exists, and is a directory.</li>
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick Treats the <em>TestString</em> as a pathname and tests
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick whether or not it exists, and is a regular file.</li>
8b69a6447203b4cbd4c063010092dbe931503644trawick Treats the <em>TestString</em> as a pathname and tests
8b69a6447203b4cbd4c063010092dbe931503644trawick whether or not it exists, and is a regular file with size greater
8b69a6447203b4cbd4c063010092dbe931503644trawick than zero.</li>
8b69a6447203b4cbd4c063010092dbe931503644trawick Treats the <em>TestString</em> as a pathname and tests
8b69a6447203b4cbd4c063010092dbe931503644trawick whether or not it exists, and is a symbolic link.</li>
8b69a6447203b4cbd4c063010092dbe931503644trawick <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick permissions)<br />
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick Treats the <em>TestString</em> as a pathname and tests
f6ba728fd666800e11b36452f7ad76ec5fcff653trawick whether or not it exists, and has executable permissions.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick These permissions are determined according to
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick the underlying OS.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest)<br />
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick Checks whether or not <em>TestString</em> is a valid file,
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick 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>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest)<br />
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick 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
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick subrequest to do the check, so use it with care -
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick it can impact your server's performance!</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick All of these tests can
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick also be prefixed by an exclamation mark ('!') to
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick negate their meaning.
4fb787199739239f1162e8ff35cbf42c9b452b8ftrawick <li>You can also set special flags for
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick <strong><code>[</code><em>flags</em><code>]</code></strong>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick as the third argument to the <code>RewriteCond</code>
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick directive, where <em>flags</em> is a comma-separated list of any of the
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick following flags:
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick This makes the test case-insensitive - differences
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick between 'A-Z' and 'a-z' are ignored, both in the
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick expanded <em>TestString</em> and the <em>CondPattern</em>.
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick This flag is effective only for comparisons between
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick <em>TestString</em> and <em>CondPattern</em>. It has no
6500ceb45a2075fad36a0dc5c86a23858bf9c84etrawick effect on filesystem and subrequest checks.</li>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick Use this to combine rule conditions with a local OR
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick instead of the implicit AND. Typical example:
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host1.* [OR]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host2.* [OR]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{REMOTE_HOST} ^host3.*
e6114dbc138189372015ea6ed63bc757645922a7trawickRewriteRule ...some special stuff for any of these hosts...
1b7ea70f150ac2343f7086af4df0b81749885eb1trawick Without this flag you would have to write the condition/rule
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick pair three times.
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 />
e6114dbc138189372015ea6ed63bc757645922a7trawick Using this flag might break proper caching of the response if
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick the representation of this response varies on the value of this header.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick So this flag should be only used if the meaning of the Vary header
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick is well understood.
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick <p>To rewrite the Homepage of a site according to the
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick ``<code>User-Agent:</code>'' header of the request, you can
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick use the following: </p>
1f5a6b18eb1d06210b03a7c8ea7a07506f5949ddtrawickRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawickRewriteRule ^/$ /homepage.max.html [L]
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawickRewriteRule ^/$ /homepage.min.html [L]
e6114dbc138189372015ea6ed63bc757645922a7trawickRewriteRule ^/$ /homepage.std.html [L]
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick <p>Explanation: If you use a browser which identifies itself
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
e6114dbc138189372015ea6ed63bc757645922a7trawick get the max homepage (which could include frames, or other special
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick If you use the Lynx browser (which is terminal-based), then
e6114dbc138189372015ea6ed63bc757645922a7trawick you get the min homepage (which could be a version designed for
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick easy, text-only browsing).
88c0d6d1cfdecfa8c2b6d7ae2482f06755cd7887trawick 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>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
d66e2366f1cceb0e2b107020fe61e36d090b6d9ctrawick<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 <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 <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>
182d9b96e04124d14c9f539109fb4e8cbd360d36trawick <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<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<div class="directive-section"><h2><a name="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">Directive</a></h2>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the lock file used for <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
8b69a6447203b4cbd4c063010092dbe931503644trawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
8b69a6447203b4cbd4c063010092dbe931503644trawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
8b69a6447203b4cbd4c063010092dbe931503644trawick <p>This directive sets the filename for a synchronization
8b69a6447203b4cbd4c063010092dbe931503644trawick lockfile which mod_rewrite needs to communicate with <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
8b69a6447203b4cbd4c063010092dbe931503644trawick <em>programs</em>. Set this lockfile to a local path (not on a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick NFS-mounted device) when you want to use a rewriting
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick map-program. It is not required for other types of rewriting
82cfc46bc66803541d4a1436462268d6495d20b1trawick<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<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
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 <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
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>Server Root</em>. The directive should occur only once per
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick server config.</p>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick rewriting actions it is not recommended to set
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <em>Filename</em> to <code>/dev/null</code>, because
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick although the rewriting engine does not then output to a
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick logfile it still creates the logfile output internally.
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick <strong>This will slow down the server with no advantage
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick to the administrator!</strong> To disable logging either
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick remove or comment out the <code class="directive">RewriteLog</code>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickdocument for details on how your security could be compromised if the
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickdirectory where logfiles are stored is writable by anyone other than
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawickthe user that starts the server.
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>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>The <code class="directive">RewriteLogLevel</code> directive sets the
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick verbosity level of the rewriting logfile. The default level 0
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick means no logging, while 9 or more means that practically all
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick actions are logged.</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>To disable the logging of rewriting actions simply set
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <em>Level</em> to 0. This disables all rewrite action
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick dramatically! Use the rewriting logfile at a
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawickRewriteLogLevel 3
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="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
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<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
1f576a0c7b9f39240f32f6061c05006dd6735f67trawick <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
fcd5c4e9e126e867eb270ed2d4138348cb1e46e5trawick insert/substitute fields through a key lookup. The source of
a8002cb6eb5309086e06721eb2cdc20b891840fftrawick this lookup can be of various types.</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <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
a8002cb6eb5309086e06721eb2cdc20b891840fftrawick mapping-function for the substitution strings of a rewriting
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick rule via one of the following constructs:</p>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <strong><code>${</code> <em>MapName</em> <code>:</code>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick <p>When such a construct occurs, the map <em>MapName</em> is
a63c98c28033ca762ca4dcbed6b3adef63580e7ctrawick consulted and the key <em>LookupKey</em> is looked-up. If the
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick key is found, the map-function construct is substituted by
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <em>SubstValue</em>. If the key is not found then it is
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick substituted by <em>DefaultValue</em> or by the empty string
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>For example, you might define a
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>You would then be able to use this map in a
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <code class="directive">RewriteRule</code> as follows:</p>
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick RewriteRule ^/ex/(.*) ${examplemap:$1}
e6114dbc138189372015ea6ed63bc757645922a7trawick <p>The following combinations for <em>MapType</em> and
e6114dbc138189372015ea6ed63bc757645922a7trawick MapType: <code>txt</code>, MapSource: Unix filesystem
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick path to valid regular file
4e2fbd7af73349caa41681acc2ec43d6d7011beatrawick <p>This is the standard rewriting map feature where the
## map.txt -- rewriting map
Ralf.S.Engelschall rse # Bastard Operator From Hell
Mr.Joe.Average joe # Mr. Average
## map.txt -- rewriting map
<p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
# ...put here any transformations or lookups...
<p>This uses <code class="module"><a href="/mod/mod_dbd.html">mod_dbd</a></code> to implement a rewritemap
<div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
<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#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
<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#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<p>Some hints on the syntax of <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
<strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: Any character of the class ``chars''
<strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: Not a character of the class ``chars''
<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>
URL-mapping directives (such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
<p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
<dt>'<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
in Apache when <code class="module"><a href="/mod/mod_include.html">mod_include</a></code> tries to find out
<p>Note: <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> must be enabled in order
Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file to be
<p>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files. To enable the
<p>The rewrite engine may also be used in <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> sections with the same
virtual host context, rather than in a <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> section.</p>
<p>Although rewrite rules are syntactically permitted in <code class="directive"><a href="/mod/core.html#location"><Location></a></code> sections, this
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a></p>
<p class="apache">Copyright 2007 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>