mod_rewrite.html.en revision 4e6d765a1b53690664877065e6b6c741c1b96937
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem 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,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem of server variables, environment variables, HTTP
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem headers, or time stamps. Even external database lookups in
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem various formats can be used to achieve highly 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<code>.htaccess</code>) and can 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>
4c36c711036219c80d5517d35be68a4769c15291slive<li><img alt="" src="/images/down.gif" /> <a href="#vhosts">Rewriting in Virtual Hosts</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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem initially requested</em>, that is, <em>before</em> any
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rewriting. This is important to note 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
4c36c711036219c80d5517d35be68a4769c15291slive</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
4c36c711036219c80d5517d35be68a4769c15291slive<h2><a name="vhosts" id="vhosts">Rewriting in Virtual Hosts</a></h2>
4c36c711036219c80d5517d35be68a4769c15291slive <p>By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> configuration
4c36c711036219c80d5517d35be68a4769c15291slive settings from the main server context are not inherited by
4c36c711036219c80d5517d35be68a4769c15291slive virtual hosts. To make the main server settings apply to virtual
4c36c711036219c80d5517d35be68a4769c15291slive hosts, you must place the following directives in each <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> section:</p>
4c36c711036219c80d5517d35be68a4769c15291slive RewriteEngine On<br />
f736cd11585a35572d5f42accf026eb667848434slive RewriteOptions Inherit
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<code>.htaccess</code>). In such a case, it will act locally,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem stripping the local directory prefix before processing, and applying
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rewrite rules only to the remainder. When processing is complete, the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem prefix 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem filepath itself. <strong>However, for most websites, URLs are NOT
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directly related to physical filename paths, so this
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem assumption will often be wrong!</strong> Therefore, you can
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemrelated to physical file paths, you will need to use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<code class="directive">RewriteBase</code> in every <code>.htaccess</code>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemfile 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)
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>This seems very complicated, but is in fact
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem correct Apache internal processing. Because the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem per-directory rewriting comes late in the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem process, the rewritten request
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem has to be re-injected into the Apache kernel.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This is not the serious overhead it may seem to be -
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem this re-injection is completely internal to the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Apache server (and the same procedure is used by
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem many other operations within Apache).</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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rule condition. One or more <code class="directive">RewriteCond</code>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem directive. The following rule is then only used if both
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p><em>TestString</em> is a string which can contain the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive following expanded constructs in addition to plain text:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteRule backreferences</strong>: These are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem backreferences of the form <strong><code>$N</code></strong>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (0 <= N <= 9), which provide access to the grouped
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem parts (in parentheses) of the pattern, from the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>RewriteRule</code> which is subject to the current
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteCond backreferences</strong>: These are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem backreferences of the form <strong><code>%N</code></strong>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (1 <= N <= 9), which provide access to the grouped
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem parts (again, in parentheses) of the pattern, from the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of conditions.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem expansions of the form <strong><code>${mapname:key|default}</code></strong>.
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem mod_rewrite include those below.</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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem can be safely used regardless of whether or not
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem contain the same value - the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>request_rec</code> structure of the Apache server.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem The first name is the commonly known CGI variable name
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem while the second is the appropriate counterpart of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive REQUEST_URI (which contains the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>uri</code> field of <code>request_rec</code>).</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{ENV:variable}</code>, where <em>variable</em> can be
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem any environment variable, is also available.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem 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>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{SSL:variable}</code>, where <em>variable</em> is the
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd name of an <a href="mod_ssl.html#envvars">SSL environment
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem variable</a>, 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:
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{HTTP:header}</code>, where <em>header</em> can be
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem any HTTP MIME-header name, can always be used to obtain the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem value of a header sent in the HTTP request.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the value of the HTTP header
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl <p>If a HTTP header is used in a condition this header is added to
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl the Vary header of the response in case the condition evaluates to
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl to true for the request. It is <strong>not</strong> added if the
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl condition evaluates to false for the request. Adding the HTTP header
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl to the Vary header of the response is needed for proper caching.</p>
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl <p>It has to be kept in mind that conditions follow a short circuit
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl so that certain conditions might not be evaluated at all.</p></li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{LA-U:variable}</code> can be used for look-aheads which perform
06ba4a61654b3763ad65f52283832ebf058fdf1cslive an internal (URL-based) sub-request to determine the final
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem value of <em>variable</em>. This can be used to access
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem variable for rewriting which is not available at the current
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem stage, but will be set in a later phase.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>For instance, to rewrite according to the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem per-server context (<code>httpd.conf</code> file) you must
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem variable is set by the authorization phases, which come
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>after</em> the URL translation phase (during which mod_rewrite
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem operates).</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{REMOTE_USER}</code> in that context.</p></li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%{LA-F:variable}</code> can be used to perform an internal
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (filename-based) sub-request, to determine the final value
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem of <em>variable</em>. Most of the time, this is the same as
06ba4a61654b3763ad65f52283832ebf058fdf1cslive LA-U above.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem a regular expression which is applied to the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>TestString</em> is first evaluated, before being 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:
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong><CondPattern</strong>' (lexicographically
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem precedes)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>CondPattern</em> as a plain string and
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem compares it lexicographically to <em>TestString</em>. True if
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>>CondPattern</strong>' (lexicographically
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem follows)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>CondPattern</em> as a plain string and
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem compares it lexicographically to <em>TestString</em>. True if
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>=CondPattern</strong>' (lexicographically
97a9a944b5887e91042b019776c41d5dd74557aferikabele equal)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>CondPattern</em> as a plain string and
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem compares it lexicographically to <em>TestString</em>. True if
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem equal, character for 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a directory.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a regular file.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a regular file with size greater
06ba4a61654b3763ad65f52283832ebf058fdf1cslive than zero.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a symbolic link.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
4e3cdb85620921a8a120fe22edbccae708f4f34end permissions)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and has executable permissions.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem These permissions are determined according to
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the underlying OS.</li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Checks whether or not <em>TestString</em> is a valid file,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive accessible via all the server's currently-configured
06ba4a61654b3763ad65f52283832ebf058fdf1cslive access controls for that path. This uses an internal
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem subrequest to do the check, so use it with care -
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem it can impact your server's performance!</li>
97a9a944b5887e91042b019776c41d5dd74557aferikabele subrequest)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Checks whether or not <em>TestString</em> is a valid URL,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive accessible via all the server's currently-configured
06ba4a61654b3763ad65f52283832ebf058fdf1cslive access controls for that path. This uses an internal
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem subrequest to do the check, so use it with care -
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem it can impact your server's performance!</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive All of these tests can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive also be prefixed by an exclamation mark ('!') to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive negate their meaning.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>You can also set special flags for
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>[</code><em>flags</em><code>]</code></strong>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem as the third argument to the <code>RewriteCond</code>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem directive, where <em>flags</em> is a comma-separated list of any of the
22d5d84393d960a2027f472036f3fee15d7dbce9nd following flags:
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This makes the test case-insensitive - differences
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem between 'A-Z' and 'a-z' are ignored, 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>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem 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...
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Without this flag you would have to write the condition/rule
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem pair three times.
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl If a HTTP header is used in the condition, this flag prevents
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl this header from being added to the Vary header of the response. <br />
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl Using this flag might break proper caching of the response if
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl the representation of this response varies on the value of this header.
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl So this flag should be only used if the meaning of the Vary header
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl is well understood.
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]
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Explanation: If you use a browser which identifies itself
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem get the max homepage (which could include frames, or other special
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem If you use the Lynx browser (which is terminal-based), then
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem you get the min homepage (which could be a version designed for
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem easy, text-only browsing).
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem If neither of these conditions apply (you use any other browser,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem or your browser identifies itself as something non-standard), you get
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the std (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>
4c36c711036219c80d5517d35be68a4769c15291slive <p>Note that rewrite configurations are not
4c36c711036219c80d5517d35be68a4769c15291slive inherited by virtual hosts. This means that you need to have a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteEngine on</code> directive for each virtual host
4c36c711036219c80d5517d35be68a4769c15291slive in which you wish to use rewrite rules.</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>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemdocument for details on how 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>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <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
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen compile-time default will be chosen.</p>
9f7f8f89dfb9115b0b9493049a6ca1ecd8508242rbowen <p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Here, the source is an internal Apache function.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Currently you cannot create your own, but the following
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem functions already exist:</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Converts the key to all upper case.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Converts the key to all lower case.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Translates special characters in the key to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive hex-encodings.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Translates hex-encodings in the 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem create it you can use a language of your choice, but
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the result has to be an executable program (either
06ba4a61654b3763ad65f52283832ebf058fdf1cslive object-code or a script with the magic cookie trick
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>This program is started once, when the Apache server
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem is started, 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...
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem If this program hangs, it will cause Apache to hang
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem when trying to use the relevant rewrite rule.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>A common mistake is to use buffered I/O on
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>stdout</code>. Avoid this, as it will cause a deadloop!
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem ``<code>$|=1</code>'' is used above, to prevent this.</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>The <code class="directive"><a href="#rewritelock">RewriteLock</a></code> directive can
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem be used to define a lockfile which mod_rewrite can use to synchronize
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem communication with the mapping program. By default no such
06ba4a61654b3763ad65f52283832ebf058fdf1cslive synchronization takes place.</li>
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd MapSource: An SQL SELECT statement that takes a single
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd argument and returns a single value.</p>
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd <p>This uses <code class="module"><a href="/mod/mod_dbd.html">mod_dbd</a></code> to implement a rewritemap
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd by lookup in an SQL database. There are two forms:
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd <code>fastdbd</code> caches database lookups internally,
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd <code>dbd</code> doesn't. So <code>dbd</code> incurs a
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd performance penalty but responds immediately if the database
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd contents are updated, while <code>fastdbd</code> is more
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd efficient but won't re-read database contents until server
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd restart.</p>
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd <p>If a query returns more than one row, a random row from
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisd the result set is used.</p>
4c881d2fffa365e2e0c5e25eb1cf77f4f9406e44chrisdRewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem configuration. The <em>Option</em> string can currently
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem only be one of the following:</p>
0203b896e484dfb877111aceffb812401d0f216and <dd>This forces the current configuration to inherit the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem 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
96147932f199be4ad038778e702c13a2f79051c0slive <em>Pattern</em> <em>Substitution</em> [<em>flags</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">RewriteRule</code> directive is the real
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rewriting workhorse. The directive can occur more than once,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem with each instance defining a single rewrite rule. The
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem order in which these rules are defined is important - this is the order
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem in which they will be applied at run-time.</p>
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl expression</a>. On the first RewriteRule it is applied to the
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl <a href="/directive-dict.html#Syntax">URL-path</a> of the request;
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl subsequent patterns are applied to the output of the last matched
8c8c2e71c84babf0e8c4b35819c7c5b3be014cfenoodl RewriteRule.</p>
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <em>Pattern</em> will initially be matched against the part of the
96147932f199be4ad038778e702c13a2f79051c0slive URL after the hostname and port, and before the query string. If you wish
96147932f199be4ad038778e702c13a2f79051c0slive to match against the hostname, port, or query string, use a
96147932f199be4ad038778e702c13a2f79051c0slive <code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
96147932f199be4ad038778e702c13a2f79051c0slive <code>%{QUERY_STRING}</code> variables respectively.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Some hints on the syntax of <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: Any character of the class ``chars''
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: Not a character of the class ``chars''
06ba4a61654b3763ad65f52283832ebf058fdf1cslive text1<strong><code>|</code></strong>text2 Alternative: text1 or text2
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>?</code></strong> 0 or 1 occurrences of the preceding text
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>*</code></strong> 0 or N occurrences of the preceding text (N > 0)
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>+</code></strong> 1 or N occurrences of the preceding text (N > 1)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (used either to set the borders of an alternative as above, or
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem to make backreferences, where the <strong>N</strong>th group can
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem be referred to on the RHS of a RewriteRule as <code>$</code><strong>N</strong>)
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong><code>\</code></strong>char escape the given char
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (for instance, to specify the chars "<code>.[]()</code>" <em>etc.</em>)
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>For more information about regular expressions, have a look at the
96147932f199be4ad038778e702c13a2f79051c0slive perl regular expression manpage ("<a href="http://www.perldoc.com/perlre.html">perldoc
630c456b6461158be6cc5c5483735e27b13b4ad5nd perlre</a>"). If you are interested in more detailed
06ba4a61654b3763ad65f52283832ebf058fdf1cslive information about regular expressions and their variants
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (POSIX regex etc.) the following book is dedicated to 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 />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>In mod_rewrite, the NOT character
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem ('<code>!</code>') is also available as a possible pattern
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem prefix. This enables you 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>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemWhen using the NOT character to negate a pattern, you cannot include
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemgrouped wildcard parts in that pattern. This is because, when the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluempattern does NOT match (ie, the negation matches), there are no
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemcontents for the groups. Thus, if negated patterns are used, you
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemcannot use <code>$N</code> in the substitution string!
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
96147932f199be4ad038778e702c13a2f79051c0slive rewrite rule is the string that replaces the original URL-path that
96147932f199be4ad038778e702c13a2f79051c0slive was matched by <em>Pattern</em>. The <em>Substitution</em> may
96147932f199be4ad038778e702c13a2f79051c0slive <dd>Designates the location on the file-system of the resource
96147932f199be4ad038778e702c13a2f79051c0slive to be delivered to the client.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <dd>A <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>-relative path to the
96147932f199be4ad038778e702c13a2f79051c0slive resource to be served. Note that <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
96147932f199be4ad038778e702c13a2f79051c0slive tries to guess whether you have specified a file-system path
96147932f199be4ad038778e702c13a2f79051c0slive or a URL-path by checking to see if the first segement of the
96147932f199be4ad038778e702c13a2f79051c0slive path exists at the root of the file-system. For example, if
96147932f199be4ad038778e702c13a2f79051c0slive <code>/www/file.html</code>, then this will be treated as a
96147932f199be4ad038778e702c13a2f79051c0slive URL-path <em>unless</em> a directory named <code>www</code>
96147932f199be4ad038778e702c13a2f79051c0slive exists at the root or your file-system, in which case it will
96147932f199be4ad038778e702c13a2f79051c0slive be treated as a file-system path. If you wish other
96147932f199be4ad038778e702c13a2f79051c0slive URL-mapping directives (such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
96147932f199be4ad038778e702c13a2f79051c0slive described below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <dd>If an absolute URL is specified,
96147932f199be4ad038778e702c13a2f79051c0slive <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
96147932f199be4ad038778e702c13a2f79051c0slive hostname matches the current host. If it does, the scheme and
96147932f199be4ad038778e702c13a2f79051c0slive hostname are stripped out and the resulting path is treated as
96147932f199be4ad038778e702c13a2f79051c0slive a URL-path. Otherwise, an external redirect is performed for
96147932f199be4ad038778e702c13a2f79051c0slive the given URL. To force an external redirect back to the
96147932f199be4ad038778e702c13a2f79051c0slive current host, see the <code>[R]</code> flag below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <dd>A dash indicates that no substitution should be performed
96147932f199be4ad038778e702c13a2f79051c0slive (the existing path is passed through untouched). This is used
96147932f199be4ad038778e702c13a2f79051c0slive when a flag (see below) needs to be applied without changing
96147932f199be4ad038778e702c13a2f79051c0slive the path.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive <p>In addition to plain text, the <em>Substition</em> string can include</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>back-references (<code>$N</code>) to the RewriteRule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern</li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>back-references (<code>%N</code>) to the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteCond pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>server-variables as in rule condition test-strings
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Back-references are identifiers of the form
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.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem These three types of variables are expanded in the order above.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>As already mentioned, all rewrite rules are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem applied to the <em>Substitution</em> (in the order in which
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem they are defined
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem in the config file). The URL is <strong>completely
06ba4a61654b3763ad65f52283832ebf058fdf1cslive replaced</strong> by the <em>Substitution</em> and the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rewriting process continues until all rules have been applied,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem or it is explicitly terminated by a
96147932f199be4ad038778e702c13a2f79051c0slive <p>By default, the query string is passed through unchanged. You
96147932f199be4ad038778e702c13a2f79051c0slive can, however, create URLs in the substitution string containing
96147932f199be4ad038778e702c13a2f79051c0slive a query string part. Simply use a question mark inside the
96147932f199be4ad038778e702c13a2f79051c0slive substitution string to indicate that the following text should
96147932f199be4ad038778e702c13a2f79051c0slive be re-injected into the query string. When you want to erase an
96147932f199be4ad038778e702c13a2f79051c0slive existing query string, end the substitution string with just a
96147932f199be4ad038778e702c13a2f79051c0slive question mark. To combine new and old query strings, use the
96147932f199be4ad038778e702c13a2f79051c0slive <p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem appending <strong><code>[</code><em>flags</em><code>]</code></strong>
96147932f199be4ad038778e702c13a2f79051c0slive directive. <em>Flags</em> is a comma-separated list, surround by square
96147932f199be4ad038778e702c13a2f79051c0slive brackets, of any of the following flags: </p>
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl <dd><p>Apache has to unescape URLs before mapping them,
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl so backreferences will be unescaped at the time they are applied.
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl Using the B flag, non-alphanumeric characters in backreferences
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl will be escaped. For example, consider the rule:</p>
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl <pre><code> RewriteRule RewriteRule ^(.*)$ index.php?show=$1 </code></pre>
1e483b59c4b4124ab0036d26b147ad93629943b7noodl <p>This will map <code>/C++</code> to <code>index.php?show=/C++</code>.
1e483b59c4b4124ab0036d26b147ad93629943b7noodl <code>index.php?show=/C++</code>, because the <code>%2b</code>
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl has been unescaped. With the B flag, it will instead map to
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl <p>This escaping is particularly necessary in a proxy situation,
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl when the backend may break if presented with an unescaped URL.</p>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen This flag chains the current rule with the next rule
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen (which itself can be chained with the following rule,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem and so on). This has the following effect: if a rule
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem matches, then processing continues as usual -
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the flag has no effect. If the rule does
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <strong>not</strong> match, then all following chained
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem rules are skipped. For instance, it can be used to remove the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem ``<code>.www</code>'' part, inside a per-directory rule set,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen when you let an external redirect happen (where the
8a7ed8b6e3f5b266680dba1c890d1b9c6c0426efnoodl <dt>'<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>]]'
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This sets a cookie in the client's browser. The cookie's name
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>VAL</em>. The <em>domain</em> field is the domain of the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem cookie, such as '.apache.org', the optional <em>lifetime</em>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen is the lifetime of the cookie in minutes, and the optional
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This forces an environment variable named <em>VAR</em> to
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen be set to the value <em>VAL</em>, where <em>VAL</em> can
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code>%N</code>) which will be expanded. You can use this
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem flag more than once, to set more than one variable. The
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem variables can later be dereferenced in many situations, most commonly
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem from within XSSI (via <code><!--#echo
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem var="VAR"--></code>) or CGI (<code>$ENV{'VAR'}</code>).
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem You can also dereference the variable in a later RewriteCond pattern, using
8a571abb6573d916da05fc8b9f04fd944ad45803slive information from URLs, while maintaining a record of that information.</dd>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This forces the current URL to be forbidden - it immediately
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem sends back a HTTP response of 403 (FORBIDDEN).
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Use this flag in conjunction with
06ba4a61654b3763ad65f52283832ebf058fdf1cslive appropriate RewriteConds to conditionally block some
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This forces the current URL to be gone - it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive immediately sends back a HTTP response of 410 (GONE). Use
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag to mark pages which no longer exist as gone.</dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen Force the Content-handler of the target file to be
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <em>Content-handler</em>. For instance, this can be used to
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem simulate the <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> directive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code>,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem which internally forces all files
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen inside the mapped directory to have a handler of
8ed0917f332087770872e032b248b2e1e689df3bslive here and don't apply any more rewrite rules. This corresponds
8ed0917f332087770872e032b248b2e1e689df3bslive <code>break</code> command in C. Use this flag to prevent the
8ed0917f332087770872e032b248b2e1e689df3bslive currently rewritten URL from being rewritten further by
8ed0917f332087770872e032b248b2e1e689df3bslive following rules. Remember, however, that if the
8ed0917f332087770872e032b248b2e1e689df3bslive <code class="directive">RewriteRule</code> generates an internal
8ed0917f332087770872e032b248b2e1e689df3bslive redirect (which frequently occurs when rewriting in a
8ed0917f332087770872e032b248b2e1e689df3bslive per-directory context), this will reinject the request and
8ed0917f332087770872e032b248b2e1e689df3bslive will cause processing to be repeated starting from the first
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Re-run the rewriting process (starting again with the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem first rewriting rule). This time, the URL to match is no longer
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the original URL, but rather the URL returned by the last rewriting rule.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive This corresponds to the Perl <code>next</code> command or
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem this flag to restart the rewriting process -
8a571abb6573d916da05fc8b9f04fd944ad45803slive to immediately go to the top of the loop.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <strong>Be careful not to create an infinite
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem ignoring difference between 'A-Z' and
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen 'a-z' when <em>Pattern</em> is matched against the current
8a571abb6573d916da05fc8b9f04fd944ad45803slive (no URI escaping of
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This flag prevents 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem from happening. This allows percent symbols to appear in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen the output, as in
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
8a571abb6573d916da05fc8b9f04fd944ad45803slive (not for internal
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem in Apache when <code class="module"><a href="/mod/mod_include.html">mod_include</a></code> tries to find out
06ba4a61654b3763ad65f52283832ebf058fdf1cslive information about possible directory default files
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<code>index.xxx</code> files). On sub-requests it is not
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem always useful, and can even cause errors, if
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the complete set of rules are applied. Use this flag to
8a571abb6573d916da05fc8b9f04fd944ad45803slive exclude some rules.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <p>To decide whether or not to use this rule: if you
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem prefix URLs with CGI-scripts, to force them to be
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem processed by the CGI-script, it's likely that you
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem will run into problems (or significant overhead) on
8a571abb6573d916da05fc8b9f04fd944ad45803slive sub-requests. In these cases, use this flag.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This flag forces the substitution part to be internally
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem sent as a proxy request and immediately (rewrite
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem processing stops here) put through the <a href="mod_proxy.html">proxy module</a>. You must make
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen sure that the substitution string is a valid URI
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (typically starting with
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem handled by the Apache proxy module. If not, you will 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,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem to map remote content into the namespace of the local
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Note: <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> must be enabled in order
9b82bd7c7f2083318e7856831dede324534308bcrbowen to use this flag.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive (pass through to next
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This flag forces the rewrite 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem enable post-processing of the output of
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem various URI-to-filename translators. For example, to rewrite
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>, and then
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code>:
97a9a944b5887e91042b019776c41d5dd74557aferikabele RewriteRule ^/abc(.*) /def$1 [PT]<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Alias /def /ghi
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>filename=/def/...</code> as a full API-compliant
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URI-to-filename translator should do. Then
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem URI-to-filename transition, which will fail.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Note: <strong>You must use this flag if you want to
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem mix directives from different modules which allow
06ba4a61654b3763ad65f52283832ebf058fdf1cslive URL-to-filename translators</strong>. The typical example
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem is the use of <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> and
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
b5407b0669a6a7175c84859e727d133399e4fa51slive <p>The <code>PT</code> flag implies the <code>L</code> flag:
b5407b0669a6a7175c84859e727d133399e4fa51slive rewriting will be stopped in order to pass the request to
b5407b0669a6a7175c84859e727d133399e4fa51slive the next phase of processing.</p>
8a571abb6573d916da05fc8b9f04fd944ad45803slive (query string
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem This flag forces the rewrite engine to append a query
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem string part of the substitution string to the existing string,
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen instead of replacing it. Use this when you want to add more
8a571abb6573d916da05fc8b9f04fd944ad45803slive data to the query string via a rewrite rule.</dd>
8a571abb6573d916da05fc8b9f04fd944ad45803slive [=<em>code</em>]' (force <a id="redirect" name="redirect">redirect</a>)</dt><dd>
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen <code>http://thishost[:thisport]/</code> (which makes the
173a6aaf8f8d2c818ab71d3781400e521051a565rbowen new URL a URI) to force a external redirection. If no
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>code</em> is given, a HTTP response of 302 (MOVED
8a571abb6573d916da05fc8b9f04fd944ad45803slive TEMPORARILY) will be returned. If you want to use other
8a571abb6573d916da05fc8b9f04fd944ad45803slive response codes, simply specify the appropriate number or use
8a571abb6573d916da05fc8b9f04fd944ad45803slive one of the following symbolic names: <code>temp</code>
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>seeother</code>. Use this for rules to canonicalize
8a571abb6573d916da05fc8b9f04fd944ad45803slive the URL and return it to the client - to translate
8a571abb6573d916da05fc8b9f04fd944ad45803slive ``<code>/~</code>'' into ``<code>/u/</code>'', or to always
8a571abb6573d916da05fc8b9f04fd944ad45803slive append a slash to <code>/u/</code><em>user</em>, etc.<br />
8a571abb6573d916da05fc8b9f04fd944ad45803slive <strong>Note:</strong> When you use this flag, make sure
8a571abb6573d916da05fc8b9f04fd944ad45803slive that the substitution field is a valid URL! Otherwise, you
8a571abb6573d916da05fc8b9f04fd944ad45803slive will be redirecting to an invalid location. Remember that
8a571abb6573d916da05fc8b9f04fd944ad45803slive this flag on its own will only prepend
8a571abb6573d916da05fc8b9f04fd944ad45803slive <code>http://thishost[:thisport]/</code> to the URL, and
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting will continue. Usually, you will want to stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting at this point, and redirect immediately. To stop
8a571abb6573d916da05fc8b9f04fd944ad45803slive rewriting, you should add the 'L' flag.</p>
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive <p>While this is typically used for redirects, any valid status
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive code can be given here. If the status code is outside the redirect
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive range (300-399), then the <em>Substitution</em> string is dropped
758cbf6f938a9e5b39422509d1e39b7078c1a1dcslive and rewriting is stopped as if the <code>L</code> flag was
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <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
8a571abb6573d916da05fc8b9f04fd944ad45803slive 'chain|C' flag!)</dd>
20189240503ef2c8f5dc6e2248b57faab4b23b5and Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file to be
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem set up 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]
de68ca33425122cf4a880859013e08e84f8143a5covener<p> When the substitution string begins with a string
de68ca33425122cf4a880859013e08e84f8143a5covenerresembling "/~user" (via explicit text or backreferences), mod_rewrite performs
de68ca33425122cf4a880859013e08e84f8143a5covenerhome directory expansion independent of the presence or configuration
4e6d765a1b53690664877065e6b6c741c1b96937covenerof <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>.</p>
de68ca33425122cf4a880859013e08e84f8143a5covener<p> This expansion does not occur when the <em>PT</em>
de68ca33425122cf4a880859013e08e84f8143a5covenerflag is used on the <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
de68ca33425122cf4a880859013e08e84f8143a5covenerdirective.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<p>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files. To enable the
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowerewrite engine for these files you need to set
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe"<code>Options FollowSymLinks</code>" must be enabled. If your
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwroweadministrator has disabled override of <code>FollowSymLinks</code> for
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowea user's directory, then you cannot use the rewrite engine. This
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowerestriction is required for security reasons.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<p>When using the rewrite engine in <code>.htaccess</code> files the
06ba4a61654b3763ad65f52283832ebf058fdf1csliveper-directory prefix (which always is the same for a specific
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluemdirectory) is automatically <em>removed</em> for the pattern matching
06ba4a61654b3763ad65f52283832ebf058fdf1csliveand automatically <em>added</em> after the substitution has been
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowedone. This feature is essential for many sorts of rewriting; without
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowethis, you would always have to match the parent directory, which is
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowenot always possible. There is one exception: If a substitution string
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowestarts with <code>http://</code>, then the directory prefix will
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<strong>not</strong> be added, and an external redirect (or proxy
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowethroughput, if using flag <strong>P</strong>) is forced. See the
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<code class="directive"><a href="#rewritebase">RewriteBase</a></code> directive for
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowemore information.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<p>The rewrite engine may also be used in <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> sections with the same
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwroweprefix-matching rules as would be applied to <code>.htaccess</code>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowefiles. It is usually simpler, however, to avoid the prefix substitution
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowecomplication by putting the rewrite rules in the main server or
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowevirtual host context, rather than in a <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> section.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<p>Although rewrite rules are syntactically permitted in <code class="directive"><a href="/mod/core.html#location"><Location></a></code> sections, this
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwroweshould never be necessary and is unsupported.</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <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---------------------------------------------- ----------------------------------
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 invalid, not supported
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 [R] invalid, not supported
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 [P] invalid, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<code>/physical/path/to/somepath/.htacccess</code>, with
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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
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
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a></p>
50337bc37d6a337217f0295bc57aaac558517c11jim<p class="apache">Copyright 2007 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
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>