mod_rewrite.html.en revision 4e3cdb85620921a8a120fe22edbccae708f4f34e
97a9a944b5887e91042b019776c41d5dd74557aferikabele<?xml version="1.0" encoding="ISO-8859-1"?>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
97a9a944b5887e91042b019776c41d5dd74557aferikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki This file is generated from xml source: DO NOT EDIT
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd -->
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<title>mod_rewrite - Apache HTTP Server</title>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<body>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="page-header">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<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>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p class="apache">Apache HTTP Server Version 2.1</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<img alt="" src="/images/feather.gif" /></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="path">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<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-project/">Documentation</a> &gt; <a href="../">Version 2.1</a> &gt; <a href="./">Modules</a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="page-content">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="preamble"><h1>Apache Module mod_rewrite</h1>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="toplang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndURLs on the fly</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 1.3 and later</td></tr></table>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h3>Summary</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <blockquote>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>``The great thing about mod_rewrite is it gives you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive all the configurability and flexibility of Sendmail.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive The downside to mod_rewrite is that it gives you all
97a9a944b5887e91042b019776c41d5dd74557aferikabele the configurability and flexibility of Sendmail.''</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="cite">-- <cite>Brian Behlendorf</cite><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele Apache Group</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </blockquote>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <blockquote>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>`` Despite the tons of examples and docs,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite is voodoo. Damned cool voodoo, but still
97a9a944b5887e91042b019776c41d5dd74557aferikabele voodoo. ''</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="cite">-- <cite>Brian Moore</cite><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele bem@news.cmc.net</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele </blockquote>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Welcome to mod_rewrite, the Swiss Army Knife of URL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive manipulation!</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This module uses a rule-based rewriting engine (based on a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive regular-expression parser) to rewrite requested URLs on the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fly. It supports an unlimited number of rules and an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive unlimited number of attached rule conditions for each rule to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive provide a really flexible and powerful URL manipulation
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mechanism. The URL manipulations can depend on various tests,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for instance server variables, environment variables, HTTP
06ba4a61654b3763ad65f52283832ebf058fdf1cslive headers, time stamps and even external database lookups in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive various formats can be used to achieve a really granular URL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matching.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This module operates on the full URLs (including the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path-info part) both in per-server context
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>httpd.conf</code>) and per-directory context
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>.htaccess</code>) and can even generate query-string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive parts on result. The rewritten result can lead to internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sub-processing, external request redirection or even to an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive internal proxy throughput.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>But all this functionality and flexibility has its
06ba4a61654b3763ad65f52283832ebf058fdf1cslive drawback: complexity. So don't expect to understand this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive entire module in just one day.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This module was invented and originally written in April
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 1996 and gifted exclusively to the The Apache Group in July 1997
06ba4a61654b3763ad65f52283832ebf058fdf1cslive by</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <a href="http://www.engelschall.com/"><code>Ralf S.
97a9a944b5887e91042b019776c41d5dd74557aferikabele Engelschall</code></a><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <a href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <a href="http://www.engelschall.com/"><code>www.engelschall.com</code></a>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="quickview"><h3 class="directives">Directives</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<ul id="toc">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritelock">RewriteLock</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</ul>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h3>Topics</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<ul id="topics">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#Internal">Internal Processing</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#EnvVar">Environment Variables</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#Solutions">Practical Solutions</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</ul></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="section">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="Internal" id="Internal">Internal Processing</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The internal processing of this module is very complex but
06ba4a61654b3763ad65f52283832ebf058fdf1cslive needs to be explained once even to the average user to avoid
06ba4a61654b3763ad65f52283832ebf058fdf1cslive common mistakes and to let you exploit its full
06ba4a61654b3763ad65f52283832ebf058fdf1cslive functionality.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<h3><a name="InternalAPI" id="InternalAPI">API Phases</a></h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>First you have to understand that when Apache processes a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive HTTP request it does this in phases. A hook for each of these
06ba4a61654b3763ad65f52283832ebf058fdf1cslive phases is provided by the Apache API. Mod_rewrite uses two of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive these hooks: the URL-to-filename translation hook which is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive used after the HTTP request has been read but before any
06ba4a61654b3763ad65f52283832ebf058fdf1cslive authorization starts and the Fixup hook which is triggered
06ba4a61654b3763ad65f52283832ebf058fdf1cslive after the authorization phases and after the per-directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslive config files (<code>.htaccess</code>) have been read, but
06ba4a61654b3763ad65f52283832ebf058fdf1cslive before the content handler is activated.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>So, after a request comes in and Apache has determined the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive corresponding server (or virtual server) the rewriting engine
06ba4a61654b3763ad65f52283832ebf058fdf1cslive starts processing of all mod_rewrite directives from the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-server configuration in the URL-to-filename phase. A few
06ba4a61654b3763ad65f52283832ebf058fdf1cslive steps later when the final data directories are found, the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-directory configuration directives of mod_rewrite are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive triggered in the Fixup phase. In both situations mod_rewrite
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewrites URLs either to new URLs or to filenames, although
06ba4a61654b3763ad65f52283832ebf058fdf1cslive there is no obvious distinction between them. This is a usage
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of the API which was not intended to be this way when the API
06ba4a61654b3763ad65f52283832ebf058fdf1cslive was designed, but as of Apache 1.x this is the only way
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite can operate. To make this point more clear
06ba4a61654b3763ad65f52283832ebf058fdf1cslive remember the following two points:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>Although mod_rewrite rewrites URLs to URLs, URLs to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive filenames and even filenames to filenames, the API
06ba4a61654b3763ad65f52283832ebf058fdf1cslive currently provides only a URL-to-filename hook. In Apache
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 2.0 the two missing hooks will be added to make the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive processing more clear. But this point has no drawbacks for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the user, it is just a fact which should be remembered:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Apache does more in the URL-to-filename hook than the API
06ba4a61654b3763ad65f52283832ebf058fdf1cslive intends for it.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Unbelievably mod_rewrite provides URL manipulations in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-directory context, <em>i.e.</em>, within
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>.htaccess</code> files, although these are reached
06ba4a61654b3763ad65f52283832ebf058fdf1cslive a very long time after the URLs have been translated to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive filenames. It has to be this way because
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>.htaccess</code> files live in the filesystem, so
06ba4a61654b3763ad65f52283832ebf058fdf1cslive processing has already reached this stage. In other
06ba4a61654b3763ad65f52283832ebf058fdf1cslive words: According to the API phases at this time it is too
06ba4a61654b3763ad65f52283832ebf058fdf1cslive late for any URL manipulations. To overcome this chicken
06ba4a61654b3763ad65f52283832ebf058fdf1cslive and egg problem mod_rewrite uses a trick: When you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive manipulate a URL/filename in per-directory context
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite first rewrites the filename back to its
06ba4a61654b3763ad65f52283832ebf058fdf1cslive corresponding URL (which is usually impossible, but see
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the <code>RewriteBase</code> directive below for the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive trick to achieve this) and then initiates a new internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sub-request with the new URL. This restarts processing of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the API phases.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Again mod_rewrite tries hard to make this complicated
06ba4a61654b3763ad65f52283832ebf058fdf1cslive step totally transparent to the user, but you should
06ba4a61654b3763ad65f52283832ebf058fdf1cslive remember here: While URL manipulations in per-server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive context are really fast and efficient, per-directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewrites are slow and inefficient due to this chicken and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive egg problem. But on the other hand this is the only way
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite can provide (locally restricted) URL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive manipulations to the average user.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Don't forget these two points!</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<h3><a name="InternalRuleset" id="InternalRuleset">Ruleset Processing</a></h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Now when mod_rewrite is triggered in these two API phases, it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive reads the configured rulesets from its configuration
06ba4a61654b3763ad65f52283832ebf058fdf1cslive structure (which itself was either created on startup for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-server context or during the directory walk of the Apache
06ba4a61654b3763ad65f52283832ebf058fdf1cslive kernel for per-directory context). Then the URL rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive engine is started with the contained ruleset (one or more
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rules together with their conditions). The operation of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URL rewriting engine itself is exactly the same for both
06ba4a61654b3763ad65f52283832ebf058fdf1cslive configuration contexts. Only the final result processing is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive different. </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The order of rules in the ruleset is important because the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting engine processes them in a special (and not very
06ba4a61654b3763ad65f52283832ebf058fdf1cslive obvious) order. The rule is this: The rewriting engine loops
97a9a944b5887e91042b019776c41d5dd74557aferikabele through the ruleset rule by rule (<code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives) and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive when a particular rule matches it optionally loops through
06ba4a61654b3763ad65f52283832ebf058fdf1cslive existing corresponding conditions (<code>RewriteCond</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directives). For historical reasons the conditions are given
06ba4a61654b3763ad65f52283832ebf058fdf1cslive first, and so the control flow is a little bit long-winded. See
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Figure 1 for more details.</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<p class="figure">
97a9a944b5887e91042b019776c41d5dd74557aferikabele <img src="/images/mod_rewrite_fig1.gif" width="428" height="385" alt="[Needs graphics capability to display]" /><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <dfn>Figure 1:</dfn>The control flow through the rewriting ruleset
97a9a944b5887e91042b019776c41d5dd74557aferikabele</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>As you can see, first the URL is matched against the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Pattern</em> of each rule. When it fails mod_rewrite
06ba4a61654b3763ad65f52283832ebf058fdf1cslive immediately stops processing this rule and continues with the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive next rule. If the <em>Pattern</em> matches, mod_rewrite looks
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for corresponding rule conditions. If none are present, it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive just substitutes the URL with a new value which is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive constructed from the string <em>Substitution</em> and goes on
06ba4a61654b3763ad65f52283832ebf058fdf1cslive with its rule-looping. But if conditions exist, it starts an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive inner loop for processing them in the order that they are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive listed. For conditions the logic is different: we don't match
06ba4a61654b3763ad65f52283832ebf058fdf1cslive a pattern against the current URL. Instead we first create a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive string <em>TestString</em> by expanding variables,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive back-references, map lookups, <em>etc.</em> and then we try
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to match <em>CondPattern</em> against it. If the pattern
06ba4a61654b3763ad65f52283832ebf058fdf1cslive doesn't match, the complete set of conditions and the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive corresponding rule fails. If the pattern matches, then the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive next condition is processed until no more conditions are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive available. If all conditions match, processing is continued
06ba4a61654b3763ad65f52283832ebf058fdf1cslive with the substitution of the URL with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Substitution</em>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<h3><a name="quoting" id="quoting">Quoting Special Characters</a></h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>As of Apache 1.3.20, special characters in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> and <em>Substitution</em> strings can be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive escaped (that is, treated as normal characters without their
06ba4a61654b3763ad65f52283832ebf058fdf1cslive usual special meaning) by prefixing them with a slosh ('\')
06ba4a61654b3763ad65f52283832ebf058fdf1cslive character. In other words, you can include an actual
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dollar-sign character in a <em>Substitution</em> string by
06ba4a61654b3763ad65f52283832ebf058fdf1cslive using '<code>\$</code>'; this keeps mod_rewrite from trying
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to treat it as a backreference.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<h3><a name="InternalBackRefs" id="InternalBackRefs">Regex Back-Reference Availability</a></h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>One important thing here has to be remembered: Whenever you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive use parentheses in <em>Pattern</em> or in one of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>, back-references are internally created
06ba4a61654b3763ad65f52283832ebf058fdf1cslive which can be used with the strings <code>$N</code> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%N</code> (see below). These are available for creating
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the strings <em>Substitution</em> and <em>TestString</em>.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Figure 2 shows to which locations the back-references are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive transfered for expansion.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<p class="figure">
97a9a944b5887e91042b019776c41d5dd74557aferikabele <img src="/images/mod_rewrite_fig2.gif" width="381" height="179" alt="[Needs graphics capability to display]" /><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <dfn>Figure 2:</dfn> The back-reference flow through a rule.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>We know this was a crash course on mod_rewrite's internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive processing. But you will benefit from this knowledge when
06ba4a61654b3763ad65f52283832ebf058fdf1cslive reading the following documentation of the available
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directives.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="section">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="EnvVar" id="EnvVar">Environment Variables</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This module keeps track of two additional (non-standard)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CGI/SSI environment variables named <code>SCRIPT_URL</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive and <code>SCRIPT_URI</code>. These contain the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>logical</em> Web-view to the current resource, while the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive standard CGI/SSI variables <code>SCRIPT_NAME</code> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>SCRIPT_FILENAME</code> contain the <em>physical</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive System-view. </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Notice: These variables hold the URI/URL <em>as they were
06ba4a61654b3763ad65f52283832ebf058fdf1cslive initially requested</em>, <em>i.e.</em>, <em>before</em> any
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting. This is important because the rewriting process is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive primarily used to rewrite logical URLs to physical
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pathnames.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSCRIPT_FILENAME=/u/rse/.www/index.html
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSCRIPT_URL=/u/rse/
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSCRIPT_URI=http://en1.engelschall.com/u/rse/
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="section">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="Solutions" id="Solutions">Practical Solutions</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>We also have an <a href="/misc/rewriteguide.html">URL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Rewriting Guide</a> available, which provides a collection of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive practical solutions for URL-based problems. There you can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive find real-life rulesets and additional information about
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>See usage for information.</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteBase</code> directive explicitly
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sets the base URL for per-directory rewrites. As you will see
97a9a944b5887e91042b019776c41d5dd74557aferikabele below, <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive can be used in per-directory config files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>.htaccess</code>). There it will act locally,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>i.e.</em>, the local directory prefix is stripped at this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive stage of processing and your rewriting rules act only on the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive remainder. At the end it is automatically added back to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path. The default setting is; <code class="directive">RewriteBase</code> <em>physical-directory-path</em></p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>When a substitution occurs for a new URL, this module has
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to re-inject the URL into the server processing. To be able
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to do this it needs to know what the corresponding URL-prefix
06ba4a61654b3763ad65f52283832ebf058fdf1cslive or URL-base is. By default this prefix is the corresponding
06ba4a61654b3763ad65f52283832ebf058fdf1cslive filepath itself. <strong>But at most websites URLs are NOT
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directly related to physical filename paths, so this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive assumption will usually be wrong!</strong> There you have to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive use the <code>RewriteBase</code> directive to specify the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive correct URL-prefix.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"> If your webserver's URLs are <strong>not</strong> directly
06ba4a61654b3763ad65f52283832ebf058fdf1csliverelated to physical file paths, you have to use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<code class="directive">RewriteBase</code> in every <code>.htaccess</code>
97a9a944b5887e91042b019776c41d5dd74557aferikabelefiles where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p> For example, assume the following per-directory config file:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# /abc/def/.htaccess -- per-dir config file for directory /abc/def
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# has a 'Alias /xyz /abc/def' directive <em>e.g.</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteEngine On
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# let the server know that we were reached via /xyz and not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# via the physical path prefix /abc/def
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteBase /xyz
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# now the rewriting rules
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^oldstuff\.html$ newstuff.html
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>In the above example, a request to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/xyz/oldstuff.html</code> gets correctly rewritten to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the physical file <code>/abc/def/newstuff.html</code>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>For Apache Hackers</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<p>The following list gives detailed information about
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the internal processing steps:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRequest:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /xyz/oldstuff.html
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveInternal Processing:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /xyz/oldstuff.html -&gt; /abc/def/oldstuff.html (per-server Alias)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /abc/def/oldstuff.html -&gt; /abc/def/newstuff.html (per-dir RewriteRule)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /abc/def/newstuff.html -&gt; /xyz/newstuff.html (per-dir RewriteBase)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /xyz/newstuff.html -&gt; /abc/def/newstuff.html (per-server Alias)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveResult:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /abc/def/newstuff.html
06ba4a61654b3763ad65f52283832ebf058fdf1cslive</pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This seems very complicated but is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the correct Apache internal processing, because the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-directory rewriting comes too late in the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive process. So, when it occurs the (rewritten) request
06ba4a61654b3763ad65f52283832ebf058fdf1cslive has to be re-injected into the Apache kernel! BUT:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive While this seems like a serious overhead, it really
06ba4a61654b3763ad65f52283832ebf058fdf1cslive isn't, because this re-injection happens fully
06ba4a61654b3763ad65f52283832ebf058fdf1cslive internally to the Apache server and the same
06ba4a61654b3763ad65f52283832ebf058fdf1cslive procedure is used by many other operations inside
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Apache. So, you can be sure the design and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive implementation is correct.</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <em>TestString</em> <em>CondPattern</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteCond</code> directive defines a
97a9a944b5887e91042b019776c41d5dd74557aferikabele rule condition. Precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directive with one
06ba4a61654b3763ad65f52283832ebf058fdf1cslive or more <code class="directive">RewriteCond</code> directives. The following
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rule is only used if its pattern matches the current
06ba4a61654b3763ad65f52283832ebf058fdf1cslive state of the URI <strong>and</strong> if these additional
06ba4a61654b3763ad65f52283832ebf058fdf1cslive conditions apply too.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><em>TestString</em> is a string which can contains the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following expanded constructs in addition to plain text:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteRule backreferences</strong>: These are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive backreferences of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>$N</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (0 &lt;= N &lt;= 9) which provide access to the grouped
06ba4a61654b3763ad65f52283832ebf058fdf1cslive parts (parenthesis!) of the pattern from the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive corresponding <code>RewriteRule</code> directive (the one
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following the current bunch of <code>RewriteCond</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directives).
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteCond backreferences</strong>: These are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive backreferences of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>%N</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (1 &lt;= N &lt;= 9) which provide access to the grouped
06ba4a61654b3763ad65f52283832ebf058fdf1cslive parts (parentheses!) of the pattern from the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteCond</code> directive in the current bunch
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of conditions.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteMap expansions</strong>: These are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive expansions of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>${mapname:key|default}</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive See <a href="#mapfunc">the documentation for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteMap</a> for more details.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>Server-Variables</strong>: These are variables of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>}</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive where <em>NAME_OF_VARIABLE</em> can be a string taken
06ba4a61654b3763ad65f52283832ebf058fdf1cslive from the following list:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>HTTP headers:</th> <th>connection &amp; request:</th> <th />
97a9a944b5887e91042b019776c41d5dd74557aferikabele </tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_USER_AGENT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_REFERER<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_COOKIE<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_FORWARDED<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_HOST<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_PROXY_CONNECTION<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_ACCEPT<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_ADDR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_HOST<br />
74a6de79356cd15d2e47065087785e36dd65aa41nd REMOTE_PORT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_USER<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_IDENT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_METHOD<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SCRIPT_FILENAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele PATH_INFO<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele QUERY_STRING<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele AUTH_TYPE<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <td />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>server internals:</th> <th>system stuff:</th> <th>specials:</th>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele DOCUMENT_ROOT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_ADMIN<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_NAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_ADDR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_PORT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_PROTOCOL<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_SOFTWARE<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_YEAR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_MON<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_DAY<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_HOUR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_MIN<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_SEC<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_WDAY<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele API_VERSION<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele THE_REQUEST<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_URI<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_FILENAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele IS_SUBREQ<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>These variables all
06ba4a61654b3763ad65f52283832ebf058fdf1cslive correspond to the similarly named HTTP
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MIME-headers, C variables of the Apache server or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>struct tm</code> fields of the Unix system.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Most are documented elsewhere in the Manual or in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the CGI specification. Those that are special to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mod_rewrite include:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dl>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>IS_SUBREQ</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>Will contain the text "true" if the request
06ba4a61654b3763ad65f52283832ebf058fdf1cslive currently being processed is a sub-request,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "false" otherwise. Sub-requests may be generated
06ba4a61654b3763ad65f52283832ebf058fdf1cslive by modules that need to resolve additional files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive or URIs in order to complete their tasks.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>API_VERSION</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>This is the version of the Apache module API
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the internal interface between server and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive module) in the current httpd build, as defined in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive include/ap_mmn.h. The module API version
06ba4a61654b3763ad65f52283832ebf058fdf1cslive corresponds to the version of Apache in use (in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the release version of Apache 1.3.14, for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive instance, it is 19990320:10), but is mainly of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive interest to module authors.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>THE_REQUEST</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The full HTTP request line sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser to the server (e.g., "<code>GET
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /index.html HTTP/1.1</code>"). This does not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive include any additional headers sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>REQUEST_URI</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The resource requested in the HTTP request
06ba4a61654b3763ad65f52283832ebf058fdf1cslive line. (In the example above, this would be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "/index.html".)</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>REQUEST_FILENAME</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The full local filesystem path to the file or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive script matching the request.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </dl>
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Special Notes:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
06ba4a61654b3763ad65f52283832ebf058fdf1cslive contain the same value, <em>i.e.</em>, the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>filename</code> field of the internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>request_rec</code> structure of the Apache server.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive The first name is just the commonly known CGI variable name
06ba4a61654b3763ad65f52283832ebf058fdf1cslive while the second is the consistent counterpart to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive REQUEST_URI (which contains the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>uri</code> field of <code>request_rec</code>).</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>There is the special format:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{ENV:variable}</code> where <em>variable</em> can be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive any environment variable. This is looked-up via internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Apache structures and (if not found there) via
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>getenv()</code> from the Apache server process.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>There is the special format:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{HTTP:header}</code> where <em>header</em> can be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive any HTTP MIME-header name. This is looked-up from the HTTP
06ba4a61654b3763ad65f52283832ebf058fdf1cslive request. Example: <code>%{HTTP:Proxy-Connection}</code> is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the value of the HTTP header
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>Proxy-Connection:</code>''.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>There is the special format
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{LA-U:variable}</code> for look-aheads which perform
06ba4a61654b3763ad65f52283832ebf058fdf1cslive an internal (URL-based) sub-request to determine the final
06ba4a61654b3763ad65f52283832ebf058fdf1cslive value of <em>variable</em>. Use this when you want to use a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive variable for rewriting which is actually set later in an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive API phase and thus is not available at the current stage.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive For instance when you want to rewrite according to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>REMOTE_USER</code> variable from within the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-server context (<code>httpd.conf</code> file) you have
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to use <code>%{LA-U:REMOTE_USER}</code> because this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive variable is set by the authorization phases which come
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>after</em> the URL translation phase where mod_rewrite
06ba4a61654b3763ad65f52283832ebf058fdf1cslive operates. On the other hand, because mod_rewrite implements
06ba4a61654b3763ad65f52283832ebf058fdf1cslive its per-directory context (<code>.htaccess</code> file) via
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the Fixup phase of the API and because the authorization
06ba4a61654b3763ad65f52283832ebf058fdf1cslive phases come <em>before</em> this phase, you just can use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{REMOTE_USER}</code> there.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>There is the special format:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{LA-F:variable}</code> which performs an internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (filename-based) sub-request to determine the final value
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of <em>variable</em>. Most of the time this is the same as
06ba4a61654b3763ad65f52283832ebf058fdf1cslive LA-U above.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><em>CondPattern</em> is the condition pattern,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>i.e.</em>, a regular expression which is applied to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive current instance of the <em>TestString</em>, <em>i.e.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> is evaluated and then matched against
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Remember:</strong> <em>CondPattern</em> is a
630c456b6461158be6cc5c5483735e27b13b4ad5nd <em>perl compatible regular expression</em> with some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive additions:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>You can prefix the pattern string with a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>!</code>' character (exclamation mark) to specify a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>non</strong>-matching pattern.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive There are some special variants of <em>CondPatterns</em>.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Instead of real regular expression strings you can also
06ba4a61654b3763ad65f52283832ebf058fdf1cslive use one of the following:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>&lt;CondPattern</strong>' (is lexically
97a9a944b5887e91042b019776c41d5dd74557aferikabele lower)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>CondPattern</em> as a plain string and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares it lexically to <em>TestString</em>. True if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> is lexically lower than
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>&gt;CondPattern</strong>' (is lexically
97a9a944b5887e91042b019776c41d5dd74557aferikabele greater)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>CondPattern</em> as a plain string and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares it lexically to <em>TestString</em>. True if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> is lexically greater than
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>=CondPattern</strong>' (is lexically
97a9a944b5887e91042b019776c41d5dd74557aferikabele equal)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>CondPattern</em> as a plain string and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares it lexically to <em>TestString</em>. True if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> is lexically equal to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>, i.e the two strings are exactly
06ba4a61654b3763ad65f52283832ebf058fdf1cslive equal (character by character). If <em>CondPattern</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive is just <code>""</code> (two quotation marks) this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares <em>TestString</em> to the empty string.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-d</strong>' (is
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>d</strong>irectory)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a directory.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-f</strong>' (is regular
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>f</strong>ile)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a regular file.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-s</strong>' (is regular file with
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>s</strong>ize)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a regular file with size greater
06ba4a61654b3763ad65f52283832ebf058fdf1cslive than zero.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-l</strong>' (is symbolic
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>l</strong>ink)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a symbolic link.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
4e3cdb85620921a8a120fe22edbccae708f4f34end <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
4e3cdb85620921a8a120fe22edbccae708f4f34end permissions)<br />
4e3cdb85620921a8a120fe22edbccae708f4f34end Treats the <em>TestString</em> as a pathname and tests
4e3cdb85620921a8a120fe22edbccae708f4f34end if it exists and has execution permissions. These permissions
4e3cdb85620921a8a120fe22edbccae708f4f34end are determined depending on the underlying OS.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-F</strong>' (is existing file via
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Checks if <em>TestString</em> is a valid file and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive accessible via all the server's currently-configured
06ba4a61654b3763ad65f52283832ebf058fdf1cslive access controls for that path. This uses an internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive subrequest to determine the check, so use it with care
06ba4a61654b3763ad65f52283832ebf058fdf1cslive because it decreases your servers performance!</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-U</strong>' (is existing URL via
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Checks if <em>TestString</em> is a valid URL and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive accessible via all the server's currently-configured
06ba4a61654b3763ad65f52283832ebf058fdf1cslive access controls for that path. This uses an internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive subrequest to determine the check, so use it with care
06ba4a61654b3763ad65f52283832ebf058fdf1cslive because it decreases your server's performance!</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Notice</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive All of these tests can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive also be prefixed by an exclamation mark ('!') to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive negate their meaning.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Additionally you can set special flags for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em> by appending</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code><em>flags</em><code>]</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>as the third argument to the <code>RewriteCond</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive. <em>Flags</em> is a comma-separated list of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following flags:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>nocase|NC</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>n</strong>o <strong>c</strong>ase)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This makes the test case-insensitive, <em>i.e.</em>, there
06ba4a61654b3763ad65f52283832ebf058fdf1cslive is no difference between 'A-Z' and 'a-z' both in the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive expanded <em>TestString</em> and the <em>CondPattern</em>.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag is effective only for comparisons between
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>TestString</em> and <em>CondPattern</em>. It has no
06ba4a61654b3763ad65f52283832ebf058fdf1cslive effect on filesystem and subrequest checks.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>ornext|OR</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>or</strong> next condition)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Use this to combine rule conditions with a local OR
06ba4a61654b3763ad65f52283832ebf058fdf1cslive instead of the implicit AND. Typical example:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host1.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host2.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host3.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ...some special stuff for any of these hosts...
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Without this flag you would have to write the cond/rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive three times.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Example:</strong></p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>To rewrite the Homepage of a site according to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>User-Agent:</code>'' header of the request, you can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive use the following: </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.max.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.min.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.std.html [L]
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Interpretation: If you use Netscape Navigator as your
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser (which identifies itself as 'Mozilla'), then you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive get the max homepage, which includes Frames, <em>etc.</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive If you use the Lynx browser (which is Terminal-based), then
06ba4a61654b3763ad65f52283832ebf058fdf1cslive you get the min homepage, which contains no images, no
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tables, <em>etc.</em> If you use any other browser you get
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the standard homepage.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteEngine</code> directive enables or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive disables the runtime rewriting engine. If it is set to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>off</code> this module does no runtime processing at
06ba4a61654b3763ad65f52283832ebf058fdf1cslive all. It does not even update the <code>SCRIPT_URx</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive environment variables.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Use this directive to disable the module instead of
97a9a944b5887e91042b019776c41d5dd74557aferikabele commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Note that, by default, rewrite configurations are not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive inherited. This means that you need to have a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteEngine on</code> directive for each virtual host
06ba4a61654b3763ad65f52283832ebf058fdf1cslive in which you wish to use it.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the lock file used for RewriteMap
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndsynchronization</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This directive sets the filename for a synchronization
97a9a944b5887e91042b019776c41d5dd74557aferikabele lockfile which mod_rewrite needs to communicate with <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>programs</em>. Set this lockfile to a local path (not on a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NFS-mounted device) when you want to use a rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive map-program. It is not required for other types of rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive maps.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndprocessing</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteLog</code> directive sets the name
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of the file to which the server logs any rewriting actions it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive performs. If the name does not begin with a slash
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ('<code>/</code>') then it is assumed to be relative to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Server Root</em>. The directive should occur only once per
06ba4a61654b3763ad65f52283832ebf058fdf1cslive server config.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"> To disable the logging of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting actions it is not recommended to set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Filename</em> to <code>/dev/null</code>, because
06ba4a61654b3763ad65f52283832ebf058fdf1cslive although the rewriting engine does not then output to a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive logfile it still creates the logfile output internally.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>This will slow down the server with no advantage
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to the administrator!</strong> To disable logging either
06ba4a61654b3763ad65f52283832ebf058fdf1cslive remove or comment out the <code class="directive">RewriteLog</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive or use <code>RewriteLogLevel 0</code>!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Security</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSee the <a href="/misc/security_tips.html">Apache Security Tips</a>
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedocument for details on why your security could be compromised if the
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedirectory where logfiles are stored is writable by anyone other than
06ba4a61654b3763ad65f52283832ebf058fdf1cslivethe user that starts the server.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLog "/usr/local/var/apache/logs/rewrite.log"
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndengine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteLogLevel</code> directive sets the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive verbosity level of the rewriting logfile. The default level 0
06ba4a61654b3763ad65f52283832ebf058fdf1cslive means no logging, while 9 or more means that practically all
06ba4a61654b3763ad65f52283832ebf058fdf1cslive actions are logged.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>To disable the logging of rewriting actions simply set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Level</em> to 0. This disables all rewrite action
06ba4a61654b3763ad65f52283832ebf058fdf1cslive logs.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"> Using a high value for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Level</em> will slow down your Apache server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dramatically! Use the rewriting logfile at a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Level</em> greater than 2 only for debugging!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLogLevel 3
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndApache 2.0.41 and later</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteMap</code> directive defines a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Rewriting Map</em> which can be used inside rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution strings by the mapping-functions to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive insert/substitute fields through a key lookup. The source of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive this lookup can be of various types.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the name of the map and will be used to specify a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mapping-function for the substitution strings of a rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rule via one of the following constructs:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>${</code> <em>MapName</em> <code>:</code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <em>LookupKey</em> <code>}</code><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>${</code> <em>MapName</em> <code>:</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>}</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>When such a construct occurs the map <em>MapName</em> is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive consulted and the key <em>LookupKey</em> is looked-up. If the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive key is found, the map-function construct is substituted by
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>SubstValue</em>. If the key is not found then it is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substituted by <em>DefaultValue</em> or by the empty string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if no <em>DefaultValue</em> was specified.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The following combinations for <em>MapType</em> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>MapSource</em> can be used:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>Standard Plain Text</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MapType: <code>txt</code>, MapSource: Unix filesystem
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This is the standard rewriting map feature where the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>MapSource</em> is a plain ASCII file containing
06ba4a61654b3763ad65f52283832ebf058fdf1cslive either blank lines, comment lines (starting with a '#'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive character) or pairs like the following - one per
06ba4a61654b3763ad65f52283832ebf058fdf1cslive line.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><em>MatchingKey</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>SubstValue</em></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive## map.txt -- rewriting map
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRalf.S.Engelschall rse # Bastard Operator From Hell
06ba4a61654b3763ad65f52283832ebf058fdf1csliveMr.Joe.Average joe # Mr. Average
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteMap real-to-user txt:/path/to/file/map.txt
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>Randomized Plain Text</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MapType: <code>rnd</code>, MapSource: Unix filesystem
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This is identical to the Standard Plain Text variant
06ba4a61654b3763ad65f52283832ebf058fdf1cslive above but with a special post-processing feature: After
06ba4a61654b3763ad65f52283832ebf058fdf1cslive looking up a value it is parsed according to contained
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>|</code>'' characters which have the meaning of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``or''. In other words they indicate a set of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive alternatives from which the actual returned value is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive chosen randomly. Although this sounds crazy and useless,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive it was actually designed for load balancing in a reverse
06ba4a61654b3763ad65f52283832ebf058fdf1cslive proxy situation where the looked up values are server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive names. Example:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive## map.txt -- rewriting map
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic www1|www2|www3|www4
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedynamic www5|www6
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteMap servers rnd:/path/to/file/map.txt
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>Hash File</strong><br /> MapType:
1578daeec017d3bb20cecdcdc3b0261c999730d5slive <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
1578daeec017d3bb20cecdcdc3b0261c999730d5slive path to valid regular file
1578daeec017d3bb20cecdcdc3b0261c999730d5slive
1578daeec017d3bb20cecdcdc3b0261c999730d5slive <p>Here the source is a binary format DBM file containing
1578daeec017d3bb20cecdcdc3b0261c999730d5slive the same contents as a <em>Plain Text</em> format file, but
1578daeec017d3bb20cecdcdc3b0261c999730d5slive in a special representation which is optimized for really
1578daeec017d3bb20cecdcdc3b0261c999730d5slive fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
1578daeec017d3bb20cecdcdc3b0261c999730d5slive db depending on <a href="/install.html#dbm">compile-time
ab6f5669a4cb16dbff7d791d434ba1b9c9b50928nd settings</a>. If the <em>type</em> is omitted, the
1578daeec017d3bb20cecdcdc3b0261c999730d5slive compile-time default will be chosen. You can create such a
1578daeec017d3bb20cecdcdc3b0261c999730d5slive file with any DBM tool or with the following Perl
1578daeec017d3bb20cecdcdc3b0261c999730d5slive script. Be sure to adjust it to create the appropriate
1578daeec017d3bb20cecdcdc3b0261c999730d5slive type of DBM. The example creates an NDBM file.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#!/path/to/bin/perl
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive## txt2dbm -- convert txt map to dbm format
06ba4a61654b3763ad65f52283832ebf058fdf1cslive##
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveuse NDBM_File;
06ba4a61654b3763ad65f52283832ebf058fdf1csliveuse Fcntl;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive($txtmap, $dbmmap) = @ARGV;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveopen(TXT, "&lt;$txtmap") or die "Couldn't open $txtmap!\n";
97a9a944b5887e91042b019776c41d5dd74557aferikabeletie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
97a9a944b5887e91042b019776c41d5dd74557aferikabele or die "Couldn't create $dbmmap!\n";
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivewhile (&lt;TXT&gt;) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive next if (/^\s*#/ or /^\s*$/);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveuntie %DB;
06ba4a61654b3763ad65f52283832ebf058fdf1csliveclose(TXT);
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive$ txt2dbm map.txt map.db
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>Internal Function</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MapType: <code>int</code>, MapSource: Internal Apache
06ba4a61654b3763ad65f52283832ebf058fdf1cslive function
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Here the source is an internal Apache function.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Currently you cannot create your own, but the following
06ba4a61654b3763ad65f52283832ebf058fdf1cslive functions already exists:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <li><strong>toupper</strong>:<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Converts the looked up key to all upper case.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <li><strong>tolower</strong>:<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Converts the looked up key to all lower case.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <li><strong>escape</strong>:<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Translates special characters in the looked up key to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive hex-encodings.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <li><strong>unescape</strong>:<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Translates hex-encodings in the looked up key back to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special characters.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>External Rewriting Program</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MapType: <code>prg</code>, MapSource: Unix filesystem
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Here the source is a program, not a map file. To
06ba4a61654b3763ad65f52283832ebf058fdf1cslive create it you can use the language of your choice, but
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the result has to be a executable (<em>i.e.</em>, either
06ba4a61654b3763ad65f52283832ebf058fdf1cslive object-code or a script with the magic cookie trick
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>#!/path/to/interpreter</code>' as the first
06ba4a61654b3763ad65f52283832ebf058fdf1cslive line).</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This program is started once at startup of the Apache
06ba4a61654b3763ad65f52283832ebf058fdf1cslive servers and then communicates with the rewriting engine
06ba4a61654b3763ad65f52283832ebf058fdf1cslive over its <code>stdin</code> and <code>stdout</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive file-handles. For each map-function lookup it will
06ba4a61654b3763ad65f52283832ebf058fdf1cslive receive the key to lookup as a newline-terminated string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive on <code>stdin</code>. It then has to give back the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive looked-up value as a newline-terminated string on
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>stdout</code> or the four-character string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
06ba4a61654b3763ad65f52283832ebf058fdf1cslive is no corresponding value for the given key). A trivial
06ba4a61654b3763ad65f52283832ebf058fdf1cslive program which will implement a 1:1 map (<em>i.e.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive key == value) could be:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#!/usr/bin/perl
06ba4a61654b3763ad65f52283832ebf058fdf1cslive$| = 1;
06ba4a61654b3763ad65f52283832ebf058fdf1cslivewhile (&lt;STDIN&gt;) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # ...put here any transformations or lookups...
06ba4a61654b3763ad65f52283832ebf058fdf1cslive print $_;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>But be very careful:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>``<em>Keep it simple, stupid</em>'' (KISS), because
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if this program hangs it will hang the Apache server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive when the rule occurs.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>Avoid one common mistake: never do buffered I/O on
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>stdout</code>! This will cause a deadloop! Hence
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the ``<code>$|=1</code>'' in the above example...</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <li>Use the <code class="directive"><a href="#rewritelock">RewriteLock</a></code> directive to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive define a lockfile mod_rewrite can use to synchronize the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive communication to the program. By default no such
06ba4a61654b3763ad65f52283832ebf058fdf1cslive synchronization takes place.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteMap</code> directive can occur more than
06ba4a61654b3763ad65f52283832ebf058fdf1cslive once. For each mapping-function use one
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code class="directive">RewriteMap</code> directive to declare its rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mapfile. While you cannot <strong>declare</strong> a map in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive per-directory context it is of course possible to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>use</strong> this map in per-directory context. </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Note</h3> For plain text and DBM format files the
06ba4a61654b3763ad65f52283832ebf058fdf1cslivelooked-up keys are cached in-core until the <code>mtime</code> of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslivemapfile changes or the server does a restart. This way you can have
06ba4a61654b3763ad65f52283832ebf058fdf1cslivemap-functions in rules which are used for <strong>every</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1csliverequest. This is no problem, because the external lookup only happens
06ba4a61654b3763ad65f52283832ebf058fdf1csliveonce!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
0203b896e484dfb877111aceffb812401d0f216and<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></code></td></tr>
0203b896e484dfb877111aceffb812401d0f216and<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteOptions MaxRedirects=10</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
e884f58207082fa2136d5fc86635c31252338948erikabele<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is available in Apache 2.0.45 and
0203b896e484dfb877111aceffb812401d0f216andlater</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteOptions</code> directive sets some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special options for the current per-server or per-directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslive configuration. The <em>Option</em> strings can be one of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0203b896e484dfb877111aceffb812401d0f216and <dl>
0203b896e484dfb877111aceffb812401d0f216and <dt><code>inherit</code></dt>
0203b896e484dfb877111aceffb812401d0f216and <dd>This forces the current configuration to inherit the
0203b896e484dfb877111aceffb812401d0f216and configuration of the parent. In per-virtual-server context
0203b896e484dfb877111aceffb812401d0f216and this means that the maps, conditions and rules of the main
0203b896e484dfb877111aceffb812401d0f216and server are inherited. In per-directory context this means
0203b896e484dfb877111aceffb812401d0f216and that conditions and rules of the parent directory's
0203b896e484dfb877111aceffb812401d0f216and <code>.htaccess</code> configuration are inherited.</dd>
0203b896e484dfb877111aceffb812401d0f216and
0203b896e484dfb877111aceffb812401d0f216and <dt><code>MaxRedirects=<var>number</var></code></dt>
0203b896e484dfb877111aceffb812401d0f216and <dd>In order to prevent endless loops of internal redirects
0203b896e484dfb877111aceffb812401d0f216and issued by per-directory <code class="directive"><a href="#rewriterule">RewriteRule</a></code>s, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> aborts
0203b896e484dfb877111aceffb812401d0f216and the request after reaching a maximum number of such redirects and
0203b896e484dfb877111aceffb812401d0f216and responds with an 500 Internal Server Error. If you really need
0203b896e484dfb877111aceffb812401d0f216and more internal redirects than 10 per request, you may increase
0203b896e484dfb877111aceffb812401d0f216and the default to the desired value.</dd>
0203b896e484dfb877111aceffb812401d0f216and </dl>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteRule
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <em>Pattern</em> <em>Substitution</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The cookie-flag is available in Apache 2.0.40 and later.</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteRule</code> directive is the real
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting workhorse. The directive can occur more than once.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Each directive then defines one single rewriting rule. The
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>definition order</strong> of these rules is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>important</strong>, because this order is used when
06ba4a61654b3763ad65f52283832ebf058fdf1cslive applying the rules at run-time.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
630c456b6461158be6cc5c5483735e27b13b4ad5nd a perl compatible <a id="regexp" name="regexp">regular
06ba4a61654b3763ad65f52283832ebf058fdf1cslive expression</a> which gets applied to the current URL. Here
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``current'' means the value of the URL when this rule gets
06ba4a61654b3763ad65f52283832ebf058fdf1cslive applied. This may not be the originally requested URL,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive because any number of rules may already have matched and made
06ba4a61654b3763ad65f52283832ebf058fdf1cslive alterations to it.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Some hints about the syntax of regular expressions:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Text:</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>.</code></strong> Any single character
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: One of chars
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: None of chars
06ba4a61654b3763ad65f52283832ebf058fdf1cslive text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Quantifiers:</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>?</code></strong> 0 or 1 of the preceding text
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>*</code></strong> 0 or N of the preceding text (N &gt; 0)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>+</code></strong> 1 or N of the preceding text (N &gt; 1)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Grouping:</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (either to set the borders of an alternative or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for making backreferences where the <strong>N</strong>th group can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be used on the RHS of a RewriteRule with <code>$</code><strong>N</strong>)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Anchors:</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>^</code></strong> Start of line anchor
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>$</code></strong> End of line anchor
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Escaping:</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>\</code></strong>char escape that particular char
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>)
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p>For more information about regular expressions have a look at the
630c456b6461158be6cc5c5483735e27b13b4ad5nd perl regular expression manpage ("<a href="http://www.perldoc.com/perl5.6.1/pod/perlre.html">perldoc
630c456b6461158be6cc5c5483735e27b13b4ad5nd perlre</a>"). If you are interested in more detailed
06ba4a61654b3763ad65f52283832ebf058fdf1cslive information about regular expressions and their variants
630c456b6461158be6cc5c5483735e27b13b4ad5nd (POSIX regex <em>etc.</em>) have a look at the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following dedicated book on this topic:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
97a9a944b5887e91042b019776c41d5dd74557aferikabele <em>Mastering Regular Expressions</em><br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele Jeffrey E.F. Friedl<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele Nutshell Handbook Series<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele O'Reilly &amp; Associates, Inc. 1997<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele ISBN 1-56592-257-3<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Additionally in mod_rewrite the NOT character
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ('<code>!</code>') is a possible pattern prefix. This gives
06ba4a61654b3763ad65f52283832ebf058fdf1cslive you the ability to negate a pattern; to say, for instance:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<em>if the current URL does <strong>NOT</strong> match this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern</em>''. This can be used for exceptional cases, where
06ba4a61654b3763ad65f52283832ebf058fdf1cslive it is easier to match the negative pattern, or as a last
06ba4a61654b3763ad65f52283832ebf058fdf1cslive default rule.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Notice</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveWhen using the NOT character
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to negate a pattern you cannot have grouped wildcard
06ba4a61654b3763ad65f52283832ebf058fdf1cslive parts in the pattern. This is impossible because when the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern does NOT match, there are no contents for the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive groups. In consequence, if negated patterns are used, you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cannot use <code>$N</code> in the substitution
06ba4a61654b3763ad65f52283832ebf058fdf1cslive string!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><a id="rhs" name="rhs"><em>Substitution</em></a> of a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rule is the string which is substituted for (or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive replaces) the original URL for which <em>Pattern</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matched. Beside plain text you can use</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>back-references <code>$N</code> to the RewriteRule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>back-references <code>%N</code> to the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteCond pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>server-variables as in rule condition test-strings
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>%{VARNAME}</code>)</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li><a href="#mapfunc">mapping-function</a> calls
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>${mapname:key|default}</code>)</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Back-references are <code>$</code><strong>N</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<strong>N</strong>=0..9) identifiers which will be replaced
06ba4a61654b3763ad65f52283832ebf058fdf1cslive by the contents of the <strong>N</strong>th group of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matched <em>Pattern</em>. The server-variables are the same
06ba4a61654b3763ad65f52283832ebf058fdf1cslive as for the <em>TestString</em> of a <code>RewriteCond</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive. The mapping-functions come from the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteMap</code> directive and are explained there.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive These three types of variables are expanded in the order of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the above list. </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>As already mentioned above, all the rewriting rules are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive applied to the <em>Substitution</em> (in the order of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive definition in the config file). The URL is <strong>completely
06ba4a61654b3763ad65f52283832ebf058fdf1cslive replaced</strong> by the <em>Substitution</em> and the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting process goes on until there are no more rules
06ba4a61654b3763ad65f52283832ebf058fdf1cslive unless explicitly terminated by a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code><strong>L</strong></code> flag - see below.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>There is a special substitution string named
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>-</code>' which means: <strong>NO
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution</strong>! Sounds silly? No, it is useful to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive provide rewriting rules which <strong>only</strong> match
06ba4a61654b3763ad65f52283832ebf058fdf1cslive some URLs but do no substitution, <em>e.g.</em>, in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive conjunction with the <strong>C</strong> (chain) flag to be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive able to have more than one pattern to be applied before a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution occurs.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>One more note: You can even create URLs in the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution string containing a query string part. Just use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive a question mark inside the substitution string to indicate
06ba4a61654b3763ad65f52283832ebf058fdf1cslive that the following stuff should be re-injected into the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive QUERY_STRING. When you want to erase an existing query
06ba4a61654b3763ad65f52283832ebf058fdf1cslive string, end the substitution string with just the question
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mark.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Note</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveThere is a special feature:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive When you prefix a substitution field with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>http://</code><em>thishost</em>[<em>:thisport</em>]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive then <strong>mod_rewrite</strong> automatically strips it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive out. This auto-reduction on implicit external redirect
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URLs is a useful and important feature when used in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive combination with a mapping-function which generates the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive hostname part. Have a look at the first example in the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive example section below to understand this.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Remember</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive An unconditional external
06ba4a61654b3763ad65f52283832ebf058fdf1cslive redirect to your own server will not work with the prefix
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>http://thishost</code> because of this feature. To
06ba4a61654b3763ad65f52283832ebf058fdf1cslive achieve such a self-redirect, you have to use the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>R</strong>-flag (see below).
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Additionally you can set special flags for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Substitution</em> by appending</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code><em>flags</em><code>]</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive as the third argument to the <code>RewriteRule</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive. <em>Flags</em> is a comma-separated list of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following flags: </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>redirect|R</code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele [=<em>code</em>]</strong>' (force <a id="redirect" name="redirect"><strong>r</strong>edirect</a>)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Prefix <em>Substitution</em> with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>http://thishost[:thisport]/</code> (which makes the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive new URL a URI) to force a external redirection. If no
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>code</em> is given a HTTP response of 302 (MOVED
06ba4a61654b3763ad65f52283832ebf058fdf1cslive TEMPORARILY) is used. If you want to use other response
06ba4a61654b3763ad65f52283832ebf058fdf1cslive codes in the range 300-400 just specify them as a number
06ba4a61654b3763ad65f52283832ebf058fdf1cslive or use one of the following symbolic names:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>temp</code> (default), <code>permanent</code>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>seeother</code>. Use it for rules which should
06ba4a61654b3763ad65f52283832ebf058fdf1cslive canonicalize the URL and give it back to the client,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>e.g.</em>, translate ``<code>/~</code>'' into
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>/u/</code>'' or always append a slash to
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>/u/</code><em>user</em>, etc.<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Note:</strong> When you use this flag, make
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sure that the substitution field is a valid URL! If not,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive you are redirecting to an invalid location! And remember
06ba4a61654b3763ad65f52283832ebf058fdf1cslive that this flag itself only prefixes the URL with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>http://thishost[:thisport]/</code>, rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive continues. Usually you also want to stop and do the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive redirection immediately. To stop the rewriting you also
06ba4a61654b3763ad65f52283832ebf058fdf1cslive have to provide the 'L' flag.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>forbidden|F</code></strong>' (force URL
97a9a944b5887e91042b019776c41d5dd74557aferikabele to be <strong>f</strong>orbidden)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This forces the current URL to be forbidden,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>i.e.</em>, it immediately sends back a HTTP response of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 403 (FORBIDDEN). Use this flag in conjunction with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive appropriate RewriteConds to conditionally block some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URLs.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>gone|G</code></strong>' (force URL to be
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>g</strong>one)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This forces the current URL to be gone, <em>i.e.</em>, it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive immediately sends back a HTTP response of 410 (GONE). Use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive this flag to mark pages which no longer exist as gone.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>proxy|P</code></strong>' (force
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>p</strong>roxy)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the substitution part to be internally
06ba4a61654b3763ad65f52283832ebf058fdf1cslive forced as a proxy request and immediately (<em>i.e.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rule processing stops here) put through the <a href="mod_proxy.html">proxy module</a>. You have to make
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sure that the substitution string is a valid URI
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<em>e.g.</em>, typically starting with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>http://</code><em>hostname</em>) which can be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive handled by the Apache proxy module. If not you get an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive error from the proxy module. Use this flag to achieve a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive more powerful implementation of the <a href="mod_proxy.html#proxypass">ProxyPass</a> directive,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to map some remote stuff into the namespace of the local
06ba4a61654b3763ad65f52283832ebf058fdf1cslive server.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Notice: To use this functionality make sure you have
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the proxy module compiled into your Apache server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive program. If you don't know please check whether
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>mod_proxy.c</code> is part of the ``<code>httpd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive -l</code>'' output. If yes, this functionality is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive available to mod_rewrite. If not, then you first have to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rebuild the ``<code>httpd</code>'' program with mod_proxy
06ba4a61654b3763ad65f52283832ebf058fdf1cslive enabled.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>last|L</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>l</strong>ast rule)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Stop the rewriting process here and don't apply any more
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rules. This corresponds to the Perl
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>last</code> command or the <code>break</code> command
06ba4a61654b3763ad65f52283832ebf058fdf1cslive from the C language. Use this flag to prevent the currently
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewritten URL from being rewritten further by following
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rules. For example, use it to rewrite the root-path URL
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ('<code>/</code>') to a real one, <em>e.g.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>/e/www/</code>'.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>next|N</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>n</strong>ext round)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Re-run the rewriting process (starting again with the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive first rewriting rule). Here the URL to match is again not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the original URL but the URL from the last rewriting rule.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This corresponds to the Perl <code>next</code> command or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the <code>continue</code> command from the C language. Use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive this flag to restart the rewriting process, <em>i.e.</em>,
97a9a944b5887e91042b019776c41d5dd74557aferikabele to immediately go to the top of the loop.<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>But be careful not to create an infinite
06ba4a61654b3763ad65f52283832ebf058fdf1cslive loop!</strong></li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>chain|C</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>c</strong>hained with next rule)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag chains the current rule with the next rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (which itself can be chained with the following rule,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>etc.</em>). This has the following effect: if a rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matches, then processing continues as usual, <em>i.e.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the flag has no effect. If the rule does
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>not</strong> match, then all following chained
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rules are skipped. For instance, use it to remove the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>.www</code>'' part inside a per-directory rule set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive when you let an external redirect happen (where the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>.www</code>'' part should not to occur!).</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>type|T</code></strong>=<em>MIME-type</em>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (force MIME <strong>t</strong>ype)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Force the MIME-type of the target file to be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>MIME-type</em>. For instance, this can be used to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive simulate the <code>mod_alias</code> directive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>ScriptAlias</code> which internally forces all files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive inside the mapped directory to have a MIME type of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>application/x-httpd-cgi</code>''.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>nosubreq|NS</code></strong>' (used only if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>n</strong>o internal
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>s</strong>ub-request)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the rewriting engine to skip a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rule if the current request is an internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sub-request. For instance, sub-requests occur internally
06ba4a61654b3763ad65f52283832ebf058fdf1cslive in Apache when <code>mod_include</code> tries to find out
06ba4a61654b3763ad65f52283832ebf058fdf1cslive information about possible directory default files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>index.xxx</code>). On sub-requests it is not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive always useful and even sometimes causes a failure to if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the complete set of rules are applied. Use this flag to
97a9a944b5887e91042b019776c41d5dd74557aferikabele exclude some rules.<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Use the following rule for your decision: whenever you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive prefix some URLs with CGI-scripts to force them to be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive processed by the CGI-script, the chance is high that you
06ba4a61654b3763ad65f52283832ebf058fdf1cslive will run into problems (or even overhead) on
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sub-requests. In these cases, use this flag.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>nocase|NC</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>n</strong>o <strong>c</strong>ase)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This makes the <em>Pattern</em> case-insensitive,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>i.e.</em>, there is no difference between 'A-Z' and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 'a-z' when <em>Pattern</em> is matched against the current
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URL.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>qsappend|QSA</code></strong>'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<strong>q</strong>uery <strong>s</strong>tring
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>a</strong>ppend)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the rewriting engine to append a query
06ba4a61654b3763ad65f52283832ebf058fdf1cslive string part in the substitution string to the existing one
06ba4a61654b3763ad65f52283832ebf058fdf1cslive instead of replacing it. Use this when you want to add more
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data to the query string via a rewrite rule.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>noescape|NE</code></strong>'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<strong>n</strong>o URI <strong>e</strong>scaping of
97a9a944b5887e91042b019776c41d5dd74557aferikabele output)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag keeps mod_rewrite from applying the usual URI
06ba4a61654b3763ad65f52283832ebf058fdf1cslive escaping rules to the result of a rewrite. Ordinarily,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special characters (such as '%', '$', ';', and so on)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive will be escaped into their hexcode equivalents ('%25',
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '%24', and '%3B', respectively); this flag prevents this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive from being done. This allows percent symbols to appear in
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the output, as in
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive which would turn '<code>/foo/zed</code>' into a safe
06ba4a61654b3763ad65f52283832ebf058fdf1cslive request for '<code>/bar?arg=P1=zed</code>'.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>passthrough|PT</code></strong>'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<strong>p</strong>ass <strong>t</strong>hrough to next
97a9a944b5887e91042b019776c41d5dd74557aferikabele handler)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the rewriting engine to set the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>uri</code> field of the internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>request_rec</code> structure to the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>filename</code> field. This flag is just a hack to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be able to post-process the output of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteRule</code> directives by
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>Alias</code>, <code>ScriptAlias</code>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>Redirect</code>, <em>etc.</em> directives from
06ba4a61654b3763ad65f52283832ebf058fdf1cslive other URI-to-filename translators. A trivial example to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive show the semantics: If you want to rewrite
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/abc</code> to <code>/def</code> via the rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive engine of <code>mod_rewrite</code> and then
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/def</code> to <code>/ghi</code> with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>mod_alias</code>:
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><p><code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele RewriteRule ^/abc(.*) /def$1 [PT]<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Alias /def /ghi
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive If you omit the <code>PT</code> flag then
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>mod_rewrite</code> will do its job fine,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>i.e.</em>, it rewrites <code>uri=/abc/...</code> to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>filename=/def/...</code> as a full API-compliant
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URI-to-filename translator should do. Then
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>mod_alias</code> comes and tries to do a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URI-to-filename transition which will not work.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Note: <strong>You have to use this flag if you want to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive intermix directives of different modules which contain
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URL-to-filename translators</strong>. The typical example
06ba4a61654b3763ad65f52283832ebf058fdf1cslive is the use of <code>mod_alias</code> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>mod_rewrite</code>..</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>skip|S</code></strong>=<em>num</em>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>s</strong>kip next rule(s))<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the rewriting engine to skip the next
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>num</em> rules in sequence when the current rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matches. Use this to make pseudo if-then-else constructs:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive The last rule of the then-clause becomes
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>skip=N</code> where N is the number of rules in the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive else-clause. (This is <strong>not</strong> the same as the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive 'chain|C' flag!)</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (set <strong>e</strong>nvironment variable)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This forces an environment variable named <em>VAR</em> to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive be set to the value <em>VAL</em>, where <em>VAL</em> can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive contain regexp backreferences <code>$N</code> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%N</code> which will be expanded. You can use this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive flag more than once to set more than one variable. The
06ba4a61654b3763ad65f52283832ebf058fdf1cslive variables can be later dereferenced in many situations, but
06ba4a61654b3763ad65f52283832ebf058fdf1cslive usually from within XSSI (via <code>&lt;!--#echo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive var="VAR"--&gt;</code>) or CGI (<em>e.g.</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>$ENV{'VAR'}</code>). Additionally you can dereference
06ba4a61654b3763ad65f52283832ebf058fdf1cslive it in a following RewriteCond pattern via
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>%{ENV:VAR}</code>. Use this to strip but remember
06ba4a61654b3763ad65f52283832ebf058fdf1cslive information from URLs.</li>
854cc4d3451547c2359c27870a3c354ad385a49bianh
854cc4d3451547c2359c27870a3c354ad385a49bianh <li>
08f6ab606a643554a8fbd30cf8ae1bb760bdc899slive '<strong><code>cookie|CO=</code></strong><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
db186e84034d595fdb0050244d13136b7321c75end (set <strong>co</strong>okie)<br />
854cc4d3451547c2359c27870a3c354ad385a49bianh This sets a cookie on the client's browser. The cookie's name
854cc4d3451547c2359c27870a3c354ad385a49bianh is specified by <em>NAME</em> and the value is
854cc4d3451547c2359c27870a3c354ad385a49bianh <em>VAL</em>. The <em>domain</em> field is the domain of the
08f6ab606a643554a8fbd30cf8ae1bb760bdc899slive cookie, such as '.apache.org',the optional <em>lifetime</em>
08f6ab606a643554a8fbd30cf8ae1bb760bdc899slive is the lifetime of the cookie in minutes, and the optional
08f6ab606a643554a8fbd30cf8ae1bb760bdc899slive <em>path</em> is the path of the cookie</li>
ab7fab7c5b562b3886904f616a825c2231302995yoshiki
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Note</h3> Never forget that <em>Pattern</em> is
06ba4a61654b3763ad65f52283832ebf058fdf1csliveapplied to a complete URL in per-server configuration
06ba4a61654b3763ad65f52283832ebf058fdf1cslivefiles. <strong>But in per-directory configuration files, the
06ba4a61654b3763ad65f52283832ebf058fdf1csliveper-directory prefix (which always is the same for a specific
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedirectory!) is automatically <em>removed</em> for the pattern matching
06ba4a61654b3763ad65f52283832ebf058fdf1csliveand automatically <em>added</em> after the substitution has been
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone.</strong> This feature is essential for many sorts of rewriting,
06ba4a61654b3763ad65f52283832ebf058fdf1cslivebecause without this prefix stripping you have to match the parent
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedirectory which is not always possible.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>There is one exception: If a substitution string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive starts with ``<code>http://</code>'' then the directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslive prefix will <strong>not</strong> be added and an
06ba4a61654b3763ad65f52283832ebf058fdf1cslive external redirect or proxy throughput (if flag
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>P</strong> is used!) is forced!</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Note</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive To enable the rewriting engine
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for per-directory configuration files you need to set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>RewriteEngine On</code>'' in these files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>and</strong> ``<code>Options
06ba4a61654b3763ad65f52283832ebf058fdf1cslive FollowSymLinks</code>'' must be enabled. If your
06ba4a61654b3763ad65f52283832ebf058fdf1cslive administrator has disabled override of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>FollowSymLinks</code> for a user's directory, then
06ba4a61654b3763ad65f52283832ebf058fdf1cslive you cannot use the rewriting engine. This restriction is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive needed for security reasons.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Here are all possible substitution combinations and their
06ba4a61654b3763ad65f52283832ebf058fdf1cslive meanings:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Inside per-server configuration
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<code>httpd.conf</code>)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
97a9a944b5887e91042b019776c41d5dd74557aferikabele /somepath/pathinfo</code>'':</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 [R] not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 [P] not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Inside per-directory configuration for
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>/somepath</code><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<em>i.e.</em>, file <code>.htaccess</code> in dir
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/physical/path/to/somepath</code> containing
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>RewriteBase /somepath</code>)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
97a9a944b5887e91042b019776c41d5dd74557aferikabele /somepath/localpath/pathinfo</code>'':</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Example:</strong></p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>We want to rewrite URLs of the form </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/</code> <em>Language</em> <code>/~</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Realname</em> <code>/.../</code> <em>File</em>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>into </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/u/</code> <em>Username</em> <code>/.../</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>File</em> <code>.</code> <em>Language</em>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>We take the rewrite mapfile from above and save it under
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>/path/to/file/map.txt</code>. Then we only have to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive add the following lines to the Apache server configuration
06ba4a61654b3763ad65f52283832ebf058fdf1cslive file:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLog /path/to/file/rewrite.log
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteMap real-to-user txt:/path/to/file/map.txt
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="bottomlang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div><div id="footer">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<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>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</body></html>