mod_rewrite.html.en revision 8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564
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<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<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>
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz<p class="apache">Apache HTTP Server Version 2.3</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
4b5981e276e93df97c34e4da05ca5cf8bbd937dand<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Modules</a></div>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a></p>
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
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>
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 <p>This module operates on the full URLs (including the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path-info part) both in per-server 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>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>Further details, discussion, and examples, are provided in the
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="quickview"><h3 class="directives">Directives</h3>
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>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen<li><img alt="" src="/images/down.gif" /> <a href="#quoting">Quoting Special Characters</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<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen<h2><a name="quoting" id="quoting">Quoting Special Characters</a></h2>
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
b95ae799514ad86a15610ad75808d7065e9847c9kess usual special meaning) by prefixing them with a slash ('\')
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>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="EnvVar" id="EnvVar">Environment Variables</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This module keeps track of two additional (non-standard)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive CGI/SSI environment variables named <code>SCRIPT_URL</code>
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 <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>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="Solutions" id="Solutions">Practical Solutions</a></h2>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>For numerous examples of common, and not-so-common, uses for
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen mod_rewrite, see the <a href="/rewrite/rewrite_guide.html">Rewrite
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen Guide</a>, and the <a href="/rewrite/rewrite_guide_advanced.html">Advanced Rewrite
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<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>
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 <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 <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>
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.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p> For example, assume the following per-directory config file:</p>
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
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteEngine On
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# let the server know that we were reached via /xyz and not
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteBase /xyz
06ba4a61654b3763ad65f52283832ebf058fdf1cslive# now the rewriting rules
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^oldstuff\.html$ newstuff.html
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<p>The following list gives detailed information about
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the internal processing steps:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveInternal Processing:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias)
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>
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<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
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>
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 <p><em>TestString</em> is a string which can contains the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following expanded constructs in addition to plain text:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteRule backreferences</strong>: These are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive backreferences of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (0 <= N <= 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 <strong>RewriteCond backreferences</strong>: These are
06ba4a61654b3763ad65f52283832ebf058fdf1cslive backreferences of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (1 <= N <= 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 expansions of the form
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteMap</a> for more details.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>Server-Variables</strong>: These are variables of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive from the following list:
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>HTTP headers:</th> <th>connection & request:</th> <th />
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 />
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 />
53d2fd50ff45e7c568f0588c742a5ef9edf8e275rbowen <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
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 />
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 API_VERSION<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele THE_REQUEST<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_URI<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_FILENAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele IS_SUBREQ<br />
fb82af0f0cd7b58eef19c54b086131b7e1e1e749madhum HTTPS<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>These variables all
06ba4a61654b3763ad65f52283832ebf058fdf1cslive correspond to the similarly named HTTP
06ba4a61654b3763ad65f52283832ebf058fdf1cslive MIME-headers, C variables of the Apache server or
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 <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 <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 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 <dd>The full HTTP request line sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive include any additional headers sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The resource requested in the HTTP request
06ba4a61654b3763ad65f52283832ebf058fdf1cslive line. (In the example above, this would be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The full local filesystem path to the file or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive script matching the request.</dd>
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <dd>Will contain the text "on" if the connection is
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd can be safely used regardless of whether
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded).</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
06ba4a61654b3763ad65f52283832ebf058fdf1cslive contain the same value, <em>i.e.</em>, the value of the
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 <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>
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <li>There is the special format:
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <code>%{SSL:variable}</code> where <em>variable</em> is the
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd name of an <a href="mod_ssl.html#envvars">SSL environment
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd variable</a>; this can be used whether or not
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded, but will always expand to
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd the empty string if it is not. Example:
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 <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 per-server context (<code>httpd.conf</code> file) you have
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 <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 <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 <p><strong>Remember:</strong> <em>CondPattern</em> is a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive additions:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>You can prefix the pattern string with a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>!</code>' character (exclamation mark) to specify a
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:
97a9a944b5887e91042b019776c41d5dd74557aferikabele lower)<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele greater)<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele equal)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive equal (character by character). If <em>CondPattern</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares <em>TestString</em> to the empty string.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a directory.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a regular file.</li>
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 Treats the <em>TestString</em> as a pathname and tests
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if it exists and is a symbolic link.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
4e3cdb85620921a8a120fe22edbccae708f4f34end permissions)<br />
4e3cdb85620921a8a120fe22edbccae708f4f34end if it exists and has execution permissions. These permissions
4e3cdb85620921a8a120fe22edbccae708f4f34end are determined depending on the underlying OS.</li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
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>
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
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 All of these tests can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive also be prefixed by an exclamation mark ('!') to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive negate their meaning.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Additionally you can set special flags for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code><em>flags</em><code>]</code></strong>
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 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 Use this to combine rule conditions with a local OR
06ba4a61654b3763ad65f52283832ebf058fdf1cslive instead of the implicit AND. Typical example:
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host1.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host2.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host3.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ...some special stuff for any of these hosts...
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Without this flag you would have to write the cond/rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive three times.
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>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.max.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.min.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.std.html [L]
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>
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<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>
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 <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 <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<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>
627c978514c54179736d152923478be7c8707f9bnd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the lock file used for <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
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>
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
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<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
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>
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 rewriting actions it is not recommended to set
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>
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.
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<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
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>
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 <p>To disable the logging of rewriting actions simply set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dramatically! Use the rewriting logfile at a
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLogLevel 3
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<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<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
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteMap</code> directive defines a
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 <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 <strong><code>${</code> <em>MapName</em> <code>:</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
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
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <p>For example, you might define a
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <p>You would then be able to use this map in a
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <code class="directive">RewriteRule</code> as follows:</p>
8ac3ff7008df949c096f9cd8f769c7893594f61fnd RewriteRule ^/ex/(.*) ${examplemap:$1}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The following combinations for <em>MapType</em> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>This is the standard rewriting map feature where the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive either blank lines, comment lines (starting with a '#'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive character) or pairs like the following - one per
06ba4a61654b3763ad65f52283832ebf058fdf1cslive## map.txt -- rewriting map
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRalf.S.Engelschall rse # Bastard Operator From Hell
06ba4a61654b3763ad65f52283832ebf058fdf1csliveMr.Joe.Average joe # Mr. Average
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
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
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen chosen randomly. For example, you might use the following map
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen file and directives to provide a random load balancing between
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen several back-end server, via a reverse-proxy. Images are sent
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen to one of the servers in the 'static' pool, while everything
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen else is sent to one of the 'dynamic' pool.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive## map.txt -- rewriting map
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic www1|www2|www3|www4
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedynamic www5|www6
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen<div class="example"><h3>Configuration directives</h3><p><code>
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowenRewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowen[NC,P,L]<br />
36088d24dae5b2cc8124264fc6a9ba349ba81adcrbowenRewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
1578daeec017d3bb20cecdcdc3b0261c999730d5slive <code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
1578daeec017d3bb20cecdcdc3b0261c999730d5slive path to valid regular file
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
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## txt2dbm -- convert txt map to dbm format
06ba4a61654b3763ad65f52283832ebf058fdf1csliveuse NDBM_File;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive($txtmap, $dbmmap) = @ARGV;
06ba4a61654b3763ad65f52283832ebf058fdf1csliveopen(TXT, "<$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";
06ba4a61654b3763ad65f52283832ebf058fdf1cslivewhile (<TXT>) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive next if (/^\s*#/ or /^\s*$/);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
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 Converts the looked up key to all upper case.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Converts the looked up key to all lower case.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Translates special characters in the looked up key to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive hex-encodings.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Translates hex-encodings in the looked up key back to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special characters.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive path to valid regular file
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 <p>This program is started once at startup of the Apache
06ba4a61654b3763ad65f52283832ebf058fdf1cslive servers and then communicates with the rewriting engine
06ba4a61654b3763ad65f52283832ebf058fdf1cslive file-handles. For each map-function lookup it will
06ba4a61654b3763ad65f52283832ebf058fdf1cslive receive the key to lookup as a newline-terminated string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive looked-up value as a newline-terminated string on
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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslivewhile (<STDIN>) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # ...put here any transformations or lookups...
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 <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>
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 <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>
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
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<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>
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>
844def494f17cb1ab0983427d5c3939e1a03ff8cnd<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteOptions</code> directive sets some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special options for the current per-server or per-directory
844def494f17cb1ab0983427d5c3939e1a03ff8cnd configuration. The <em>Option</em> string can be currently only one:</p>
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
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<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<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>
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>important</strong>, because this order is used when
06ba4a61654b3763ad65f52283832ebf058fdf1cslive applying the rules at run-time.</p>
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
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>
d1348237b33bc1755b9f1165eea52317465a7671nd <p>Some hints about the syntax of <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
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 <strong><code>?</code></strong> 0 or 1 of the preceding text
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>*</code></strong> 0 or N of the preceding text (N > 0)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>+</code></strong> 1 or N of the preceding text (N > 1)
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 <strong><code>\</code></strong>char escape that particular char
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>)
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
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following dedicated book on this topic:</p>
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen <em>Mastering Regular Expressions, 2nd Edition</em><br />
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen O'Reilly & Associates, Inc. 2002<br />
edc8d9e0cce625a77afd1ff87a8f955694a973e2rbowen ISBN 0-596-00289-0<br />
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>
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 <p><a id="rhs" name="rhs"><em>Substitution</em></a> of a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting rule is the string which is substituted for (or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matched. Beside plain text you can use</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>back-references <code>$N</code> to the RewriteRule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>back-references <code>%N</code> to the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteCond pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>server-variables as in rule condition test-strings
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 <p>As already mentioned above, all the rewriting rules are
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 <p>There is a special substitution string named
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution</strong>! Sounds silly? No, it is useful to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive provide rewriting rules which <strong>only</strong> match
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>
70373b9ee042e7b3be82eee14b17f510fffdacc9slive <p>The <em>Pattern</em> will not match against the query string.
70373b9ee042e7b3be82eee14b17f510fffdacc9slive Instead, you must use a <code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
70373b9ee042e7b3be82eee14b17f510fffdacc9slive <code>%{QUERY_STRING}</code> variable. You can, however, create
70373b9ee042e7b3be82eee14b17f510fffdacc9slive URLs in the substitution string containing a query string
70373b9ee042e7b3be82eee14b17f510fffdacc9slive part. Just use a question mark inside the substitution string to
70373b9ee042e7b3be82eee14b17f510fffdacc9slive indicate that the following stuff should be re-injected into the
70373b9ee042e7b3be82eee14b17f510fffdacc9slive query string. When you want to erase an existing query string,
70373b9ee042e7b3be82eee14b17f510fffdacc9slive end the substitution string with just the question mark. To
70373b9ee042e7b3be82eee14b17f510fffdacc9slive combine a new query string with an old one, use the
70373b9ee042e7b3be82eee14b17f510fffdacc9slive<div class="note"><h3>Substitution of Absolute URLs</h3>
70373b9ee042e7b3be82eee14b17f510fffdacc9slive <p>There 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
70373b9ee042e7b3be82eee14b17f510fffdacc9slive example section below to understand this.</p>
70373b9ee042e7b3be82eee14b17f510fffdacc9slive <p><strong>Remember:</strong> 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
21f4ac5ab80abe4cbe90ae0f340c29053556c52drbowen <p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">flags</a> for <em>Substitution</em> by
21f4ac5ab80abe4cbe90ae0f340c29053556c52drbowen appending</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code><em>flags</em><code>]</code></strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive. <em>Flags</em> is a comma-separated list of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following flags: </p>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag chains the current rule with the next rule
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen (which itself can be chained with the following rule,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>etc.</em>). This has the following effect: if a rule
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen matches, then processing continues as usual, <em>i.e.</em>,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the flag has no effect. If the rule does
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <strong>not</strong> match, then all following chained
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen rules are skipped. For instance, use it to remove the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen ``<code>.www</code>'' part inside a per-directory rule set
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen when you let an external redirect happen (where the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen ``<code>.www</code>'' part should not to occur!).</li>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '<strong><code>cookie|CO=</code></strong><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This sets a cookie on the client's browser. The cookie's name
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>VAL</em>. The <em>domain</em> field is the domain of the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen cookie, such as '.apache.org',the optional <em>lifetime</em>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen is the lifetime of the cookie in minutes, and the optional
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>'
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This forces an environment variable named <em>VAR</em> to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be set to the value <em>VAL</em>, where <em>VAL</em> can
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>%N</code> which will be expanded. You can use this
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen flag more than once to set more than one variable. The
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen variables can be later dereferenced in many situations, but
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen usually from within XSSI (via <code><!--#echo
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>$ENV{'VAR'}</code>). Additionally you can dereference
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen it in a following RewriteCond pattern via
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>%{ENV:VAR}</code>. Use this to strip but remember
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen information from URLs.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>forbidden|F</code></strong>' (force URL
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 <li>'<strong><code>gone|G</code></strong>' (force URL to be
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>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '<strong><code>handler|H</code></strong>=<em>Content-handler</em>'
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen Force the Content-handler of the target file to be
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>Content-handler</em>. For instance, this can be used to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>ScriptAlias</code> which internally forces all files
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen inside the mapped directory to have a handler of
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 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
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>i.e.</em>, there is no difference between 'A-Z' and
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen 'a-z' when <em>Pattern</em> is matched against the current
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen (<strong>n</strong>o URI <strong>e</strong>scaping of
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen output)<br />
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag keeps mod_rewrite from applying the usual URI
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen escaping rules to the result of a rewrite. Ordinarily,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen special characters (such as '%', '$', ';', and so on)
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen will be escaped into their hexcode equivalents ('%25',
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '%24', and '%3B', respectively); this flag prevents this
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen from being done. This allows percent symbols to appear in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the output, as in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>nosubreq|NS</code></strong>' (used only if
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 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 <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>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag forces the substitution part to be internally
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen forced as a proxy request and immediately (<em>i.e.</em>,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen rewriting rule processing stops here) put through the <a href="mod_proxy.html">proxy module</a>. You have to make
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen sure that the substitution string is a valid URI
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen handled by the Apache proxy module. If not you get an
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen error from the proxy module. Use this flag to achieve a
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen more powerful implementation of the <a href="mod_proxy.html#proxypass">ProxyPass</a> directive,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen to map some remote stuff into the namespace of the local
9b82bd7c7f2083318e7856831dede324534308bcrbowen <p>Notice: <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> must be enabled in order
9b82bd7c7f2083318e7856831dede324534308bcrbowen to use this flag.</p>
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>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 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
97a9a944b5887e91042b019776c41d5dd74557aferikabele RewriteRule ^/abc(.*) /def$1 [PT]<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Alias /def /ghi
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 URI-to-filename transition which will not work.
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
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag forces the rewriting engine to append a query
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen string part in the substitution string to the existing one
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen instead of replacing it. Use this when you want to add more
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen data to the query string via a rewrite rule.</li>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen [=<em>code</em>]</strong>' (force <a id="redirect" name="redirect"><strong>r</strong>edirect</a>)<br />
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>http://thishost[:thisport]/</code> (which makes the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen new URL a URI) to force a external redirection. If no
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen TEMPORARILY) is used. If you want to use other response
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen codes in the range 300-400 just specify them as a number
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen or use one of the following symbolic names:
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen canonicalize the URL and give it back to the client,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <p><strong>Note:</strong> When you use this flag, make
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen sure that the substitution field is a valid URL! If not,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen you are redirecting to an invalid location! And remember
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen that this flag itself only prefixes the URL with
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen continues. Usually you also want to stop and do the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen redirection immediately. To stop the rewriting you also
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen have to provide the 'L' flag.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>skip|S</code></strong>=<em>num</em>'
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This flag forces the rewriting engine to skip the next
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>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen '<strong><code>type|T</code></strong>=<em>MIME-type</em>'
20189240503ef2c8f5dc6e2248b57faab4b23b5and Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file to be
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>MIME-type</em>. For instance, this can be used to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen setup the content-type based on some conditions.
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen For example, the following snippet allows <code>.php</code> files to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be <em>displayed</em> by <code>mod_php</code> if they are called with
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]
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 <p>There is one exception: If a substitution string
06ba4a61654b3763ad65f52283832ebf058fdf1cslive starts with ``<code>http://</code>'' then the directory
06ba4a61654b3763ad65f52283832ebf058fdf1cslive external redirect or proxy throughput (if flag
06ba4a61654b3763ad65f52283832ebf058fdf1cslive To enable the rewriting engine
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for per-directory configuration files you need to set
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.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Here are all possible substitution combinations and their
06ba4a61654b3763ad65f52283832ebf058fdf1cslive meanings:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 [R] not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) otherpath$1 [P] not supported, because invalid!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
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^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
97a9a944b5887e91042b019776c41d5dd74557aferikabele /somepath/localpath/pathinfo</code>'':</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [P] not supported, because silly!
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
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^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
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
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a></p>
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirin<p class="apache">Copyright 1995-2006 The Apache Software Foundation or its licensors, as applicable.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</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>