mod_rewrite.html.en revision e619b7228ac42d9c70d6a5f02d808b0d2880080c
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<?xml version="1.0" encoding="ISO-8859-1"?>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd This file is generated from xml source: DO NOT EDIT
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd -->
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<title>mod_rewrite - Apache HTTP Server</title>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/images/favicon.ico" rel="shortcut icon" /></head>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<body>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<div id="page-header">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<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>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<p class="apache">Apache HTTP Server Version 2.3</p>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<img alt="" src="/images/feather.gif" /></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div id="path">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.3</a> &gt; <a href="./">Modules</a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div id="page-content">
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<div id="preamble"><h1>Apache Module mod_rewrite</h1>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="toplang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi</div>
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7ndURLs on the fly</td></tr>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache 1.3 and later</td></tr></table>
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem<h3>Summary</h3>
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>The <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> module uses a rule-based rewriting
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd engine, based on a regular-expression parser, to rewrite requested URLs on
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd the fly. By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> maps a URL to a filesystem
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd path. However, it can also be used to redirect one URL to another URL, or
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd to invoke an internal proxy fetch.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> provides a flexible and powerful way to
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd manipulate URLs using an unlimited number of rules. Each rule can have an
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd unlimited number of attached rule conditions, to allow you to rewrite URL
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd based on server variables, environment variables, HTTP headers, or time
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd stamps.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> operates on the full URL path, including the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd path-info section. A rewrite rule can be invoked in
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd by a rewrite rule can include a query string, or can lead to internal
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd sub-processing, external request redirection, or internal proxy
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd throughput.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>Further details, discussion, and examples, are provided in the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd</div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div id="quickview"><h3 class="directives">Directives</h3>
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun<ul id="toc">
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
316f02e3836836c82e19019ff23f90a7ebc65289nilgun<li><img alt="" src="/images/down.gif" /> <a href="#rewritelock">RewriteLock</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen<li><img alt="" src="/images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd</ul>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd</div>
b43f840409794ed298e8634f6284741f193b6c4ftakashi
22d5d84393d960a2027f472036f3fee15d7dbce9nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<table class="directive">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
50c04f297d76a57ead2fa6b73845f7563b1fc788sf<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd</table>
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl <p>The <code class="directive">RewriteBase</code> directive explicitly
a78048ccbdb6256da15e6b0e7e95355e480c2301nd sets the base URL for per-directory rewrites.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd When you use a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
ffb88a4885747797937e30a5ac8b1606da3cb4adnd in a <code>.htaccess</code> file, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> strips off
909ce17e2bd0faef7b1c294f2307f009793fd493nd the local directory prefix before processing, then rewrites the rest of
a78048ccbdb6256da15e6b0e7e95355e480c2301nd the URL. When the rewrite is completed, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd automatically adds the local directory prefix back on to the path.</p>
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe <p>If your URL path does not exist on the filesystem,
42af92a661a06b3cebc88d585aad75064a309d51nd you must use <code class="directive">RewriteBase</code> in every
42af92a661a06b3cebc88d585aad75064a309d51nd <code>.htaccess</code> file where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives. </p>
ffb88a4885747797937e30a5ac8b1606da3cb4adnd
6fe26506780e73be2a412d758af77fafdf03291and <p>The example below demonstrates how to map
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <code>http://example.com/foo/index.html</code> to
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <code>/home/www/example/newsite.html</code>, in a <code>.htaccess</code>
9649d29bb7801e0698e6a845e1a8a61534df58b3noodl file. This assumes that the content available at
9649d29bb7801e0698e6a845e1a8a61534df58b3noodl <code>http://example.com/</code> is on disk at
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <code>/home/www/example/</code>.</p>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<div class="example"><pre>
0853e1e2522c1ac17f697221758bcbd4781a7ff9ndRewriteEngine On
0853e1e2522c1ac17f697221758bcbd4781a7ff9ndRewriteBase /foo/
08cf4a15275e4cb65a424b3a1db5410bfb51085cjimRewriteRule ^index\.html$ newsite.html
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak</pre></div>
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen</div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd<table class="directive">
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin</td></tr>
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd <em>TestString</em> <em>CondPattern</em></code></td></tr>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
e8b603fa9ccf7b17b11b42df6d8916fd97c2331dnd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier</table>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd <p>The <code class="directive"><a href="#rewritecond">RewriteCond</a></code>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd directive defines a rule condition. One or more <code class="directive"><a href="#rewritecond">RewriteCond</a></code>
611049e38bfbaeb173d2d7fab2e44a48753436a1nd conditions can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directive. The following rewrite rule is then
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd used only if these conditions are met, and if the URI matches the pattern
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd specified in the rule.</p>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak<div class="section">
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak<h2><a name="TestString" id="TestString">TestString</a></h2>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <p><code><em>TestString</em></code> can contain plain text, any of the
a78048ccbdb6256da15e6b0e7e95355e480c2301nd following expanded constructs, or both.</p>
03a4ff9ac4c9b8009249010e7c53bb86ff05915and <ul>
5effc8b39fae5cd169d17f342bfc265705840014rbowen <li>
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak <strong>RewriteRule backreferences</strong>: These are
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen backreferences of the form <strong><code>$N</code></strong>
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen (1 &lt;= N &lt;= 9). They provide access to the grouped
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak parts of the current <code>RewriteRule</code> pattern. The grouped
4b5981e276e93df97c34e4da05ca5cf8bbd937dand parts of the pattern are those in parentheses.</li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <li>
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak <strong>RewriteCond backreferences</strong>: These are
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak backreferences of the form <strong><code>%N</code></strong>
2704de98885368683621b01c8f8f4e4b01557611takashi (1 &lt;= N &lt;= 9). They provide access to the grouped
2704de98885368683621b01c8f8f4e4b01557611takashi parts of the last-matched <code>RewriteCond</code> pattern. The
2704de98885368683621b01c8f8f4e4b01557611takashi grouped parts of the pattern are those in parentheses.</li>
b43f840409794ed298e8634f6284741f193b6c4ftakashi <li>
2704de98885368683621b01c8f8f4e4b01557611takashi <strong>RewriteMap expansions</strong>: These are
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd expansions of the form <strong><code>${mapname:key|default}</code></strong>.
6aadbc6fd703e73d1d419e9f06b84a4338c898f1maczniak See the <a href="#mapfunc">RewriteMap documentation</a>
c819c19c2f1ffbf3a3f12a4070cc6c3f4ea2a6f2sf for more details.
d2b809e5d72658bff23819d8b77f20e4939af541nd </li>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <li>
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier <strong>Server variables</strong>: These are variables of
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier the form
e60187855fd0488f48f37e88acde742754308d39rbowen <strong><code>%{ <em>NAME_OF_VARIABLE</em> }</code></strong>,
04bab87733a0e93a926e82311c85cd8ac06a032fnd where <em>NAME_OF_VARIABLE</em> is one of the server variables from
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd the table below:
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <table>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <th>HTTP headers:</th> <th>connection &amp; request:</th> <th />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd </tr>
5effc8b39fae5cd169d17f342bfc265705840014rbowen
5effc8b39fae5cd169d17f342bfc265705840014rbowen <tr>
27d778df0b517e1578f907d2e51eb961cd8ee5fbjim <td>
a610901168de82df5fc5d99b8759fd80e0f70aeasf HTTP_USER_AGENT<br />
a43bfa789f4e52dde53ae8e53fa0427b5c1cf977nd HTTP_REFERER<br />
a43bfa789f4e52dde53ae8e53fa0427b5c1cf977nd HTTP_COOKIE<br />
28c9d384aa958b321280b4ac886941dcad25396bnd HTTP_FORWARDED<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd HTTP_HOST<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd HTTP_PROXY_CONNECTION<br />
438b4817913a5ff55d9cad4c7ddf133330b4466ejim HTTP_ACCEPT<br />
438b4817913a5ff55d9cad4c7ddf133330b4466ejim </td>
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi
e5ce3ac0e9b720c0fa23782e29168a0810697fdetakashi <td>
604c89126c27104f659d7a51b0113e3bd435faf8fielding REMOTE_ADDR<br />
50cb7e2b30597f481fee57bac945190f06ebcc58jorton REMOTE_HOST<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd REMOTE_PORT<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd REMOTE_USER<br />
4126704c4950bfd46d32ad54e3b106ac6d868a73sf REMOTE_IDENT<br />
4126704c4950bfd46d32ad54e3b106ac6d868a73sf REQUEST_METHOD<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd SCRIPT_FILENAME<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd PATH_INFO<br />
0a69d9bb491d9810892a9949c01403a1de3c7ac2nd QUERY_STRING<br />
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier AUTH_TYPE<br />
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier </td>
5effc8b39fae5cd169d17f342bfc265705840014rbowen
5effc8b39fae5cd169d17f342bfc265705840014rbowen <td />
9652bc3a93433d52f80579062986ead2afe0d11fsf </tr>
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowe
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun <tr>
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowe </tr>
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <tr>
50cb7e2b30597f481fee57bac945190f06ebcc58jorton <td>
79b024b81f6bb3c44dce77a7552191daf8b522d2jim DOCUMENT_ROOT<br />
f772e8f448c223e5ea306f1bf92d97d968f972d5jim SERVER_ADMIN<br />
f772e8f448c223e5ea306f1bf92d97d968f972d5jim SERVER_NAME<br />
fac8c35bfb158112226ab43ddf84d59daca5dc30nd SERVER_ADDR<br />
f772e8f448c223e5ea306f1bf92d97d968f972d5jim SERVER_PORT<br />
1de1266f0ea387d6373be8415745dfd2ab876341jim SERVER_PROTOCOL<br />
1de1266f0ea387d6373be8415745dfd2ab876341jim SERVER_SOFTWARE<br />
a78048ccbdb6256da15e6b0e7e95355e480c2301nd </td>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
5effc8b39fae5cd169d17f342bfc265705840014rbowen <td>
5effc8b39fae5cd169d17f342bfc265705840014rbowen TIME_YEAR<br />
5effc8b39fae5cd169d17f342bfc265705840014rbowen TIME_MON<br />
5effc8b39fae5cd169d17f342bfc265705840014rbowen TIME_DAY<br />
a78048ccbdb6256da15e6b0e7e95355e480c2301nd TIME_HOUR<br />
a78048ccbdb6256da15e6b0e7e95355e480c2301nd TIME_MIN<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd TIME_SEC<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd TIME_WDAY<br />
a78048ccbdb6256da15e6b0e7e95355e480c2301nd TIME<br />
898711b68797304101de0882fa576c8908acfae6nd </td>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd <td>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd API_VERSION<br />
50cb7e2b30597f481fee57bac945190f06ebcc58jorton THE_REQUEST<br />
a78048ccbdb6256da15e6b0e7e95355e480c2301nd REQUEST_URI<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd REQUEST_FILENAME<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd IS_SUBREQ<br />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd HTTPS<br />
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak </td>
03c25fb6f628ac81f2ecb637d1e7502dcee783f3nd </tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd </table>
b43f840409794ed298e8634f6284741f193b6c4ftakashi </li></ul>
b43f840409794ed298e8634f6284741f193b6c4ftakashi <div class="note"><p>The following variables are specific to
4126704c4950bfd46d32ad54e3b106ac6d868a73sf <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>:</p>
4126704c4950bfd46d32ad54e3b106ac6d868a73sf <dl>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <dt><code>IS_SUBREQ</code></dt>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd <dd>Contains the text "true" if the request
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd currently being processed is a sub-request, or
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi "false" otherwise. Sub-requests may be generated
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen by modules that need to resolve additional files
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd or URIs in order to complete their tasks.</dd>
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen <dt><code>API_VERSION</code></dt>
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <dd>The version of the Apache module API contained in the
1a1356f375e36db7bee379ea0684ab389579f798rbowen current httpd build, as defined in
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen include/ap_mmn.h.</dd>
0d0ba3a410038e179b695446bb149cce6264e0abnd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd <dt><code>THE_REQUEST</code></dt>
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd <dd>The full HTTP request line sent by the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd browser to the server (e.g., "<code>GET
/index.html HTTP/1.1</code>"). This does not
include any additional headers sent by the
browser.</dd>
<dt><code>REQUEST_URI</code></dt>
<dd>The resource requested in the HTTP request
line.</dd>
<dt><code>REQUEST_FILENAME</code></dt>
<dd>The full local filesystem path of the file or
script matching the request.</dd>
<dt><code>HTTPS</code></dt>
<dd>Contains the text "on" if the connection is
using SSL/TLS, or "off" otherwise. This variable
does not depend on <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> being loaded.</dd>
</dl>
</div>
<p>Note that the <code>SCRIPT_FILENAME</code> and
<code>REQUEST_FILENAME</code>
variables both contain the value of the
<code>filename</code> field of the internal
<code>request_rec</code> structure.
If a substitution occurs and rewriting continues,
the value of both variables will be updated accordingly.
In a per-server context, before the
request is mapped to the filesystem, these variables contain the value
of <code>REQUEST_URI</code>, because the full filesystem path is not
yet known. To obtain the full filesystem
path of a request in a per-server context, use a URL-based
look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
the final value of <code>REQUEST_FILENAME</code>.</p>
<p>Other available variables include the following:</p>
<ul><li>
<code>%{ENV:<em>variable</em>}</code>, where <em>variable</em> can be
any environment variable.</li>
<li>
<code>%{SSL:<em>variable</em>}</code>, where <em>variable</em> is the
name of an <a href="mod_ssl.html#envvars">SSL environment
variable</a>. If <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is not loaded, this
will always expand to the empty string.</li>
<li>
<code>%{HTTP:<em>header</em>}</code>, where <em>header</em> can be
any HTTP MIME-header name. For example,
<code>%{HTTP:Proxy-Connection}</code> is the value of the HTTP header
``<code>Proxy-Connection:</code>''. If a HTTP header is used in a
condition, and the condition evaluates to <code>true</code>, then that
header is added to the Vary header of the response. This is used to
ensure proper caching.
If a previous condition has evaluated to <code>true</code> and the
'<strong><code>ornext|OR</code></strong>' flag is in use, later
conditions are not evaluated, and therefore headers are not added to the
Vary header.</li>
<li>
<code>%{LA-U:<em>variable</em>}</code>, which is used to perform
an internal URL-based sub-request, to determine the final
value of <em>variable</em>. This can be used to access the value of
a variable which is to be set in a later phase. For example, the
<code>REMOTE_USER</code> variable is set in the authorization phase of
processing. This comes after the URL translation phase, where rewrite
rules in <code>httpd.conf</code> are applied, but before the fixup
phase, where rewrite rules in a <code>.htaccess</code> file are applied.
Therefore, to obtain the value of the <code>REMOTE_USER</code> variable
within <code>httpd.conf</code>, you must use <code>%{LA-U:REMOTE_USER}</code>. To obtain the value of the
<code>REMOTE_USER</code> variable within a <code>.htaccess</code> file,
simply use <code>%{REMOTE_USER}</code></li>
</ul>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="CondPattern" id="CondPattern">CondPattern</a></h2>
<p><em>CondPattern</em> is the condition pattern,
a regular expression which is applied to the
current instance of the <em>TestString</em>.
<em>TestString</em> is first evaluated, before being matched against
<em>CondPattern</em>.</p>
<p><strong>Remember:</strong> <em>CondPattern</em> is a
<em>perl compatible regular expression</em> with some
additions:</p>
<ol>
<li>You can prefix the pattern string with a
'<code>!</code>' character (exclamation mark) to specify a
<strong>non</strong>-matching pattern.</li>
<li>
There are some special variants of <em>CondPatterns</em>.
Instead of real regular expression strings you can also
use one of the following:
<ul>
<li>'<strong>&lt;CondPattern</strong>' (lexicographically
precedes)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexicographically to <em>TestString</em>. True if
<em>TestString</em> lexicographically precedes
<em>CondPattern</em>.</li>
<li>'<strong>&gt;CondPattern</strong>' (lexicographically
follows)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexicographically to <em>TestString</em>. True if
<em>TestString</em> lexicographically follows
<em>CondPattern</em>.</li>
<li>'<strong>=CondPattern</strong>' (lexicographically
equal)<br />
Treats the <em>CondPattern</em> as a plain string and
compares it lexicographically to <em>TestString</em>. True if
<em>TestString</em> is lexicographically equal to
<em>CondPattern</em> (the two strings are exactly
equal, character for character). If <em>CondPattern</em>
is <code>""</code> (two quotation marks) this
compares <em>TestString</em> to the empty string.</li>
<li>'<strong>-d</strong>' (is
<strong>d</strong>irectory)<br />
Treats the <em>TestString</em> as a pathname and tests
whether or not it exists, and is a directory.</li>
<li>'<strong>-f</strong>' (is regular
<strong>f</strong>ile)<br />
Treats the <em>TestString</em> as a pathname and tests
whether or not it exists, and is a regular file.</li>
<li>'<strong>-s</strong>' (is regular file, with
<strong>s</strong>ize)<br />
Treats the <em>TestString</em> as a pathname and tests
whether or not it exists, and is a regular file with size greater
than zero.</li>
<li>'<strong>-l</strong>' (is symbolic
<strong>l</strong>ink)<br />
Treats the <em>TestString</em> as a pathname and tests
whether or not it exists, and is a symbolic link.</li>
<li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
permissions)<br />
Treats the <em>TestString</em> as a pathname and tests
whether or not it exists, and has executable permissions.
These permissions are determined according to
the underlying OS.</li>
<li>'<strong>-F</strong>' (is existing file, via
subrequest)<br />
Checks whether or not <em>TestString</em> is a valid file,
accessible via all the server's currently-configured
access controls for that path. This uses an internal
subrequest to do the check, so use it with care -
it can impact your server's performance!</li>
<li>'<strong>-U</strong>' (is existing URL, via
subrequest)<br />
Checks whether or not <em>TestString</em> is a valid URL,
accessible via all the server's currently-configured
access controls for that path. This uses an internal
subrequest to do the check, so use it with care -
it can impact your server's performance!</li>
</ul>
<div class="note"><h3>Note:</h3>
All of these tests can
also be prefixed by an exclamation mark ('!') to
negate their meaning.
</div>
</li>
<li>You can also set special flags for
<em>CondPattern</em> by appending
<strong><code>[</code><em>flags</em><code>]</code></strong>
as the third argument to the <code>RewriteCond</code>
directive, where <em>flags</em> is a comma-separated list of any of the
following flags:
<ul>
<li>'<strong><code>nocase|NC</code></strong>'
(<strong>n</strong>o <strong>c</strong>ase)<br />
This makes the test case-insensitive - differences
between 'A-Z' and 'a-z' are ignored, both in the
expanded <em>TestString</em> and the <em>CondPattern</em>.
This flag is effective only for comparisons between
<em>TestString</em> and <em>CondPattern</em>. It has no
effect on filesystem and subrequest checks.</li>
<li>
'<strong><code>ornext|OR</code></strong>'
(<strong>or</strong> next condition)<br />
Use this to combine rule conditions with a local OR
instead of the implicit AND. Typical example:
<div class="example"><pre>
RewriteCond %{REMOTE_HOST} ^host1.* [OR]
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
RewriteCond %{REMOTE_HOST} ^host3.*
RewriteRule ...some special stuff for any of these hosts...
</pre></div>
Without this flag you would have to write the condition/rule
pair three times.
</li>
<li>'<strong><code>novary|NV</code></strong>'
(<strong>n</strong>o <strong>v</strong>ary)<br />
If a HTTP header is used in the condition, this flag prevents
this header from being added to the Vary header of the response. <br />
Using this flag might break proper caching of the response if
the representation of this response varies on the value of this header.
So this flag should be only used if the meaning of the Vary header
is well understood.
</li>
</ul>
</li>
</ol>
<p><strong>Example:</strong></p>
<p>To rewrite the Homepage of a site according to the
``<code>User-Agent:</code>'' header of the request, you can
use the following: </p>
<div class="example"><pre>
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^/$ /homepage.max.html [L]
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
</pre></div>
<p>Explanation: If you use a browser which identifies itself
as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
get the max homepage (which could include frames, or other special
features).
If you use the Lynx browser (which is terminal-based), then
you get the min homepage (which could be a version designed for
easy, text-only browsing).
If neither of these conditions apply (you use any other browser,
or your browser identifies itself as something non-standard), you get
the std (standard) homepage.</p>
</div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
<p>The <code class="directive">RewriteEngine</code> directive enables or
disables the runtime rewriting engine. If it is set to
<code>off</code> this module does no runtime processing at
all. It does not even update the <code>SCRIPT_URx</code>
environment variables.</p>
<p>Use this directive to disable the module instead of
commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
<p>Note that rewrite configurations are not
inherited by virtual hosts. This means that you need to have a
<code>RewriteEngine on</code> directive for each virtual host
in which you wish to use rewrite rules.</p>
<p><code class="directive">RewriteMap</code> directives of the type <code>prg</code>
are not started during server initialization if they're defined in a
context that does not have <code class="directive">RewriteEngine</code> set to
<code>on</code></p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteLock" id="RewriteLock">RewriteLock</a> <a name="rewritelock" id="rewritelock">Directive</a></h2>
<table class="directive">
<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>
synchronization</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLock <em>file-path</em></code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
<p>This directive sets the filename for a synchronization
lockfile which mod_rewrite needs to communicate with <code class="directive"><a href="#rewritemap">RewriteMap</a></code>
<em>programs</em>. Set this lockfile to a local path (not on a
NFS-mounted device) when you want to use a rewriting
map-program. It is not required for other types of rewriting
maps.</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
processing</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
<p>The <code class="directive">RewriteLog</code> directive sets the name
of the file to which the server logs any rewriting actions it
performs. If the name does not begin with a slash
('<code>/</code>') then it is assumed to be relative to the
<em>Server Root</em>. The directive should occur only once per
server config.</p>
<div class="note"> To disable the logging of
rewriting actions it is not recommended to set
<em>Filename</em> to <code>/dev/null</code>, because
although the rewriting engine does not then output to a
logfile it still creates the logfile output internally.
<strong>This will slow down the server with no advantage
to the administrator!</strong> To disable logging either
remove or comment out the <code class="directive">RewriteLog</code>
directive or use <code>RewriteLogLevel 0</code>!
</div>
<div class="note"><h3>Security</h3>
See the <a href="/misc/security_tips.html">Apache Security Tips</a>
document for details on how your security could be compromised if the
directory where logfiles are stored is writable by anyone other than
the user that starts the server.
</div>
<div class="example"><h3>Example</h3><p><code>
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
</code></p></div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
<p>The <code class="directive">RewriteLogLevel</code> directive sets the
verbosity level of the rewriting logfile. The default level 0
means no logging, while 9 or more means that practically all
actions are logged.</p>
<p>To disable the logging of rewriting actions simply set
<em>Level</em> to 0. This disables all rewrite action
logs.</p>
<div class="note"> Using a high value for
<em>Level</em> will slow down your Apache server
dramatically! Use the rewriting logfile at a
<em>Level</em> greater than 2 only for debugging!
</div>
<div class="example"><h3>Example</h3><p><code>
RewriteLogLevel 3
</code></p></div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
Apache 2.0.41 and later</td></tr>
</table>
<p>The <code class="directive">RewriteMap</code> directive defines a
<em>Rewriting Map</em> which can be used inside rule
substitution strings by the mapping-functions to
insert/substitute fields through a key lookup. The source of
this lookup can be of various types.</p>
<p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
the name of the map and will be used to specify a
mapping-function for the substitution strings of a rewriting
rule via one of the following constructs:</p>
<p class="indent">
<strong><code>${</code> <em>MapName</em> <code>:</code>
<em>LookupKey</em> <code>}</code><br />
<code>${</code> <em>MapName</em> <code>:</code>
<em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
<code>}</code></strong>
</p>
<p>When such a construct occurs, the map <em>MapName</em> is
consulted and the key <em>LookupKey</em> is looked-up. If the
key is found, the map-function construct is substituted by
<em>SubstValue</em>. If the key is not found then it is
substituted by <em>DefaultValue</em> or by the empty string
if no <em>DefaultValue</em> was specified.</p>
<p>For example, you might define a
<code class="directive">RewriteMap</code> as:</p>
<div class="example"><p><code>
RewriteMap examplemap txt:/path/to/file/map.txt
</code></p></div>
<p>You would then be able to use this map in a
<code class="directive">RewriteRule</code> as follows:</p>
<div class="example"><p><code>
RewriteRule ^/ex/(.*) ${examplemap:$1}
</code></p></div>
<p>The following combinations for <em>MapType</em> and
<em>MapSource</em> can be used:</p>
<ul>
<li>
<strong>Standard Plain Text</strong><br />
MapType: <code>txt</code>, MapSource: Unix filesystem
path to valid regular file
<p>This is the standard rewriting map feature where the
<em>MapSource</em> is a plain ASCII file containing
either blank lines, comment lines (starting with a '#'
character) or pairs like the following - one per
line.</p>
<p class="indent">
<strong><em>MatchingKey</em>
<em>SubstValue</em></strong>
</p>
<div class="example"><h3>Example</h3><pre>
##
## map.txt -- rewriting map
##
Ralf.S.Engelschall rse # Bastard Operator From Hell
Mr.Joe.Average joe # Mr. Average
</pre></div>
<div class="example"><p><code>
RewriteMap real-to-user txt:/path/to/file/map.txt
</code></p></div>
</li>
<li>
<strong>Randomized Plain Text</strong><br />
MapType: <code>rnd</code>, MapSource: Unix filesystem
path to valid regular file
<p>This is identical to the Standard Plain Text variant
above but with a special post-processing feature: After
looking up a value it is parsed according to contained
``<code>|</code>'' characters which have the meaning of
``or''. In other words they indicate a set of
alternatives from which the actual returned value is
chosen randomly. For example, you might use the following map
file and directives to provide a random load balancing between
several back-end server, via a reverse-proxy. Images are sent
to one of the servers in the 'static' pool, while everything
else is sent to one of the 'dynamic' pool.</p>
<p>Example:</p>
<div class="example"><h3>Rewrite map file</h3><pre>
##
## map.txt -- rewriting map
##
static www1|www2|www3|www4
dynamic www5|www6
</pre></div>
<div class="example"><h3>Configuration directives</h3><p><code>
RewriteMap servers rnd:/path/to/file/map.txt<br />
<br />
RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1
[NC,P,L]<br />
RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
</code></p></div>
</li>
<li>
<strong>Hash File</strong><br /> MapType:
<code>dbm[=<em>type</em>]</code>, MapSource: Unix filesystem
path to valid regular file
<p>Here the source is a binary format DBM file containing
the same contents as a <em>Plain Text</em> format file, but
in a special representation which is optimized for really
fast lookups. The <em>type</em> can be sdbm, gdbm, ndbm, or
db depending on <a href="/install.html#dbm">compile-time
settings</a>. If the <em>type</em> is omitted, the
compile-time default will be chosen.</p>
<p>To create a dbm file from a source text file, use the <a href="/programs/httxt2dbm.html">httxt2dbm</a> utility.</p>
<div class="example"><p><code>
$ httxt2dbm -i mapfile.txt -o mapfile.map
</code></p></div>
</li>
<li>
<strong>Internal Function</strong><br />
MapType: <code>int</code>, MapSource: Internal Apache
function
<p>Here, the source is an internal Apache function.
Currently you cannot create your own, but the following
functions already exist:</p>
<ul>
<li><strong>toupper</strong>:<br />
Converts the key to all upper case.</li>
<li><strong>tolower</strong>:<br />
Converts the key to all lower case.</li>
<li><strong>escape</strong>:<br />
Translates special characters in the key to
hex-encodings.</li>
<li><strong>unescape</strong>:<br />
Translates hex-encodings in the key back to
special characters.</li>
</ul>
</li>
<li>
<strong>External Rewriting Program</strong><br />
MapType: <code>prg</code>, MapSource: Unix filesystem
path to valid regular file
<p>Here the source is a program, not a map file. To
create it you can use a language of your choice, but
the result has to be an executable program (either
object-code or a script with the magic cookie trick
'<code>#!/path/to/interpreter</code>' as the first
line).</p>
<p>This program is started once, when the Apache server
is started, and then communicates with the rewriting engine
via its <code>stdin</code> and <code>stdout</code>
file-handles. For each map-function lookup it will
receive the key to lookup as a newline-terminated string
on <code>stdin</code>. It then has to give back the
looked-up value as a newline-terminated string on
<code>stdout</code> or the four-character string
``<code>NULL</code>'' if it fails (<em>i.e.</em>, there
is no corresponding value for the given key).</p>
<p>External rewriting programs are not started if they're defined in a
context that does not have <code class="directive">RewriteEngine</code> set to
<code>on</code></p>.
<p>A trivial program which will implement a 1:1 map (<em>i.e.</em>,
key == value) could be:</p>
<div class="example"><pre>
#!/usr/bin/perl
$| = 1;
while (&lt;STDIN&gt;) {
# ...put here any transformations or lookups...
print $_;
}
</pre></div>
<p>But be very careful:</p>
<ol>
<li>``<em>Keep it simple, stupid</em>'' (KISS).
If this program hangs, it will cause Apache to hang
when trying to use the relevant rewrite rule.</li>
<li>A common mistake is to use buffered I/O on
<code>stdout</code>. Avoid this, as it will cause a deadloop!
``<code>$|=1</code>'' is used above, to prevent this.</li>
<li>The <code class="directive"><a href="#rewritelock">RewriteLock</a></code> directive can
be used to define a lockfile which mod_rewrite can use to synchronize
communication with the mapping program. By default no such
synchronization takes place.</li>
</ol>
</li>
<li>
<p><strong>SQL Query</strong><br />
MapType: <code>dbd</code> or <code>fastdbd</code>,
MapSource: An SQL SELECT statement that takes a single
argument and returns a single value.</p>
<p>This uses <code class="module"><a href="/mod/mod_dbd.html">mod_dbd</a></code> to implement a rewritemap
by lookup in an SQL database. There are two forms:
<code>fastdbd</code> caches database lookups internally,
<code>dbd</code> doesn't. So <code>dbd</code> incurs a
performance penalty but responds immediately if the database
contents are updated, while <code>fastdbd</code> is more
efficient but won't re-read database contents until server
restart.</p>
<p>If a query returns more than one row, a random row from
the result set is used.</p>
<div class="example"><h3>Example</h3><p><code>
RewriteMap myquery "fastdbd:SELECT destination FROM rewrite WHERE source = %s"
</code></p></div>
</li>
</ul>
<p>The <code class="directive">RewriteMap</code> directive can occur more than
once. For each mapping-function use one
<code class="directive">RewriteMap</code> directive to declare its rewriting
mapfile. While you cannot <strong>declare</strong> a map in
per-directory context it is of course possible to
<strong>use</strong> this map in per-directory context. </p>
<div class="note"><h3>Note</h3> For plain text and DBM format files the
looked-up keys are cached in-core until the <code>mtime</code> of the
mapfile changes or the server does a restart. This way you can have
map-functions in rules which are used for <strong>every</strong>
request. This is no problem, because the external lookup only happens
once!
</div>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
later</td></tr>
</table>
<p>The <code class="directive">RewriteOptions</code> directive sets some
special options for the current per-server or per-directory
configuration. The <em>Option</em> string can currently
only be one of the following:</p>
<dl>
<dt><code>inherit</code></dt>
<dd>This forces the current configuration to inherit the
configuration of the parent. In per-virtual-server context,
this means that the maps, conditions and rules of the main
server are inherited. In per-directory context this means
that conditions and rules of the parent directory's
<code>.htaccess</code> configuration or
<code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code>
sections are inherited. The inherited rules are virtually copied
to the section where this directive is being used. If used in
combination with local rules, the inherited rules are copied behind
the local rules. The position of this directive - below or above
of local rules - has no influence on this behavior. If local
rules forced the rewriting to stop, the inherited rules won't
be processed.</dd>
</dl>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteRule
<em>Pattern</em> <em>Substitution</em> [<em>flags</em>]</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
</table>
<p>The <code class="directive">RewriteRule</code> directive is the real
rewriting workhorse. The directive can occur more than once,
with each instance defining a single rewrite rule. The
order in which these rules are defined is important - this is the order
in which they will be applied at run-time.</p>
<p><a id="patterns" name="patterns"><em>Pattern</em></a> is
a perl compatible <a id="regexp" name="regexp">regular
expression</a>. On the first RewriteRule it is applied to the (%-encoded)
<a href="/directive-dict.html#Syntax">URL-path</a> of the request;
subsequent patterns are applied to the output of the last matched
RewriteRule.</p>
<div class="note"><h3>What is matched?</h3>
<p>The <em>Pattern</em> will initially be matched against the part of the
URL after the hostname and port, and before the query string.</p>
<p>When the RewriteRule appears in per-directory (htaccess) context, the
<em>Pattern</em> is matched against what remains of the URL after removing
the prefix that lead Apache to the current rules (see the
<code class="directive"><a href="#rewritebase">RewriteBase</a></code>). The removed prefix
always ends with a slash, meaning the matching occurs against a string which
never has a leading slash. A <em>Pattern</em> with <code>^/</code> never
matches in per-directory context.</p>
<p>If you wish to match against the hostname, port, or query string, use a
<code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
<code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
<code>%{QUERY_STRING}</code> variables respectively. If you wish to
match against the full URL-path in a per-directory (htaccess) RewriteRule,
use the <code>%{REQUEST_URI}</code> variable.</p>
</div>
<p>For some hints on <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
expressions</a>, see
the <a href="/rewrite/intro.html#regex">mod_rewrite
Introduction</a>.</p>
<p>In mod_rewrite, the NOT character
('<code>!</code>') is also available as a possible pattern
prefix. This enables you to negate a pattern; to say, for instance:
``<em>if the current URL does <strong>NOT</strong> match this
pattern</em>''. This can be used for exceptional cases, where
it is easier to match the negative pattern, or as a last
default rule.</p>
<div class="note"><h3>Note</h3>
When using the NOT character to negate a pattern, you cannot include
grouped wildcard parts in that pattern. This is because, when the
pattern does NOT match (ie, the negation matches), there are no
contents for the groups. Thus, if negated patterns are used, you
cannot use <code>$N</code> in the substitution string!
</div>
<p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
rewrite rule is the string that replaces the original URL-path that
was matched by <em>Pattern</em>. The <em>Substitution</em> may
be a:</p>
<dl>
<dt>file-system path</dt>
<dd>Designates the location on the file-system of the resource
to be delivered to the client.</dd>
<dt>URL-path</dt>
<dd>A <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>-relative path to the
resource to be served. Note that <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
tries to guess whether you have specified a file-system path
or a URL-path by checking to see if the first segment of the
path exists at the root of the file-system. For example, if
you specify a <em>Substitution</em> string of
<code>/www/file.html</code>, then this will be treated as a
URL-path <em>unless</em> a directory named <code>www</code>
exists at the root or your file-system, in which case it will
be treated as a file-system path. If you wish other
URL-mapping directives (such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
resulting URL-path, use the <code>[PT]</code> flag as
described below.</dd>
<dt>Absolute URL</dt>
<dd>If an absolute URL is specified,
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
hostname matches the current host. If it does, the scheme and
hostname are stripped out and the resulting path is treated as
a URL-path. Otherwise, an external redirect is performed for
the given URL. To force an external redirect back to the
current host, see the <code>[R]</code> flag below.</dd>
<dt><code>-</code> (dash)</dt>
<dd>A dash indicates that no substitution should be performed
(the existing path is passed through untouched). This is used
when a flag (see below) needs to be applied without changing
the path.</dd>
</dl>
<p>In addition to plain text, the <em>Substition</em> string can include</p>
<ol>
<li>back-references (<code>$N</code>) to the RewriteRule
pattern</li>
<li>back-references (<code>%N</code>) to the last matched
RewriteCond pattern</li>
<li>server-variables as in rule condition test-strings
(<code>%{VARNAME}</code>)</li>
<li><a href="#mapfunc">mapping-function</a> calls
(<code>${mapname:key|default}</code>)</li>
</ol>
<p>Back-references are identifiers of the form
<code>$</code><strong>N</strong>
(<strong>N</strong>=0..9), which will be replaced
by the contents of the <strong>N</strong>th group of the
matched <em>Pattern</em>. The server-variables are the same
as for the <em>TestString</em> of a <code>RewriteCond</code>
directive. The mapping-functions come from the
<code>RewriteMap</code> directive and are explained there.
These three types of variables are expanded in the order above.</p>
<p>As already mentioned, all rewrite rules are
applied to the <em>Substitution</em> (in the order in which
they are defined
in the config file). The URL is <strong>completely
replaced</strong> by the <em>Substitution</em> and the
rewriting process continues until all rules have been applied,
or it is explicitly terminated by a
<code><strong>L</strong></code> flag.</p>
<div class="note"><h3>Modifying the Query String</h3>
<p>By default, the query string is passed through unchanged. You
can, however, create URLs in the substitution string containing
a query string part. Simply use a question mark inside the
substitution string to indicate that the following text should
be re-injected into the query string. When you want to erase an
existing query string, end the substitution string with just a
question mark. To combine new and old query strings, use the
<code>[QSA]</code> flag.</p>
</div>
<p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
appending <strong><code>[</code><em>flags</em><code>]</code></strong>
as the third argument to the <code>RewriteRule</code>
directive. <em>Flags</em> is a comma-separated list, surround by square
brackets, of any of the following flags: </p>
<dl>
<dt>'<code>B</code>' (escape backreferences)</dt>
<dd><p>Apache has to unescape URLs before mapping them,
so backreferences will be unescaped at the time they are applied.
Using the B flag, non-alphanumeric characters in backreferences
will be escaped. For example, consider the rule:</p>
<div class="example"><p><code>
RewriteRule ^(/.*)$ /index.php?show=$1
</code></p></div>
<p>This will map <code>/C++</code> to
<code>/index.php?show=/C++</code>. But it will also map
<code>/C%2b%2b</code> to <code>/index.php?show=/C++</code>, because
the <code>%2b</code> has been unescaped. With the B flag, it will
instead map to <code>/index.php?show=/C%2b%2b</code>.</p>
<p>This escaping is particularly necessary in a proxy situation,
when the backend may break if presented with an unescaped URL.</p>
</dd>
<dt>'<code>chain|C</code>'
(chained with next rule)</dt><dd>
This flag chains the current rule with the next rule
(which itself can be chained with the following rule,
and so on). This has the following effect: if a rule
matches, then processing continues as usual -
the flag has no effect. If the rule does
<strong>not</strong> match, then all following chained
rules are skipped. For instance, it can be used to remove the
``<code>.www</code>'' part, inside a per-directory rule set,
when you let an external redirect happen (where the
``<code>.www</code>'' part should not occur!).</dd>
<dt>'<code>cookie|CO=</code><em>NAME</em>:<em>VAL</em>:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]]'
(set cookie)</dt><dd>
This sets a cookie in the client's browser. The cookie's name
is specified by <em>NAME</em> and the value is
<em>VAL</em>. The <em>domain</em> field is the domain of the
cookie, such as '.apache.org', the optional <em>lifetime</em>
is the lifetime of the cookie in minutes (0 means expires at end
of session), and the optional
<em>path</em> is the path of the cookie. If <em>secure</em>
is set to 'secure', 'true' or '1', the cookie is only transmitted via secured
connections. If <em>httponly</em> is set to 'HttpOnly', 'true' or '1', the
<code>HttpOnly</code> flag is used, making the cookie inaccessible
to JavaScript code on browsers that support this feature.</dd>
<dt>'<code>discardpathinfo|DPI'
(discard PATH_INFO)</code></dt><dd>
<p>This flag is available from 2.2.12</p>
<p>In per-directory context, the URI each <code class="directive">RewriteRule</code>
compares against is the concatenation of the current values of the URI
and PATH_INFO.</p>
<p>The current URI can be the initial URI as requested by the client, the
result of a previous round of mod_rewrite processing, or the result of
a prior rule in the current round of mod_rewrite processing.</p>
<p>In contrast, the PATH_INFO that is appended to the URI before each
rule reflects only the value of PATH_INFO before this round of
mod_rewrite processing. As a consequence, if large portions
of the URI are matched and copied into a substitution in multiple
<code class="directive">RewriteRule</code> directives, without regard for
which parts of the URI came from the current PATH_INFO, the final
URI may have multiple copies of PATH_INFO appended to it.</p>
<p>Use this flag on any substitution where the PATH_INFO that resulted
from the previous mapping of this request to the filesystem is not of
interest. This flag permanently forgets the PATH_INFO established
before this round of mod_rewrite processing began. PATH_INFO will
not be recalculated until the current round of mod_rewrite processing
completes. Subsequent rules during this round of processing will see
only the direct result of substitutions, without any PATH_INFO
appended.</p></dd>
<dt>
'<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
(set environment variable)</dt><dd>
This forces an environment variable named <em>VAR</em> to
be set to the value <em>VAL</em>, where <em>VAL</em> can
contain regexp backreferences (<code>$N</code> and
<code>%N</code>) which will be expanded. You can use this
flag more than once, to set more than one variable. The
variables can later be dereferenced in many situations, most commonly
from within XSSI (via <code>&lt;!--#echo
var="VAR"--&gt;</code>) or CGI (<code>$ENV{'VAR'}</code>).
You can also dereference the variable in a later RewriteCond pattern, using
<code>%{ENV:VAR}</code>. Use this to strip
information from URLs, while maintaining a record of that information.</dd>
<dt>'<code>forbidden|F</code>' (force URL
to be forbidden)</dt><dd>
This forces the current URL to be forbidden - it immediately
sends back a HTTP response of 403 (FORBIDDEN).
Use this flag in conjunction with
appropriate RewriteConds to conditionally block some
URLs.</dd>
<dt>'<code>gone|G</code>' (force URL to be
gone)</dt><dd>
This forces the current URL to be gone - it
immediately sends back a HTTP response of 410 (GONE). Use
this flag to mark pages which no longer exist as gone.</dd>
<dt>
'<code>handler|H</code>=<em>Content-handler</em>'
(force Content handler)</dt><dd>
Force the Content-handler of the target file to be
<em>Content-handler</em>. For instance, this can be used to
simulate the <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> directive
<code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code>,
which internally forces all files
inside the mapped directory to have a handler of
``<code>cgi-script</code>''.<br />
If used in per-directory context, there must not be a substitution
which changes the path. Use this flag in per-directory context only
with <code>-</code> (dash) as the substitution, otherwise the request
will fail.</dd>
<dt>'<code>last|L</code>'
(last rule)</dt><dd> Stop the rewriting process
here and don't apply any more rewrite rules. This corresponds
to the Perl <code>last</code> command or the
<code>break</code> command in C. Use this flag to prevent the
currently rewritten URL from being rewritten further by
following rules. Remember, however, that if the
<code class="directive">RewriteRule</code> generates an internal
redirect (which frequently occurs when rewriting in a
per-directory context), this will reinject the request and
will cause processing to be repeated starting from the first
<code class="directive">RewriteRule</code>.</dd>
<dt>'<code>next|N</code>'
(next round)</dt><dd>
Re-run the rewriting process (starting again with the
first rewriting rule). This time, the URL to match is no longer
the original URL, but rather the URL returned by the last rewriting rule.
This corresponds to the Perl <code>next</code> command or
the <code>continue</code> command in C. Use
this flag to restart the rewriting process -
to immediately go to the top of the loop.
<strong>Be careful not to create an infinite
loop!</strong></dd>
<dt>'<code>nocase|NC</code>'
(no case)</dt><dd>
This makes the <em>Pattern</em> case-insensitive,
ignoring difference between 'A-Z' and
'a-z' when <em>Pattern</em> is matched against the current
URL.</dd>
<dt>
'<code>noescape|NE</code>'
(no URI escaping of
output)</dt><dd>
This flag prevents mod_rewrite from applying the usual URI
escaping rules to the result of a rewrite. Ordinarily,
special characters (such as '%', '$', ';', and so on)
will be escaped into their hexcode equivalents ('%25',
'%24', and '%3B', respectively); this flag prevents this
from happening. This allows percent symbols to appear in
the output, as in
<div class="example"><p><code>
RewriteRule ^/foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
</code></p></div>
which would turn '<code>/foo/zed</code>' into a safe
request for '<code>/bar?arg=P1=zed</code>'.
</dd>
<dt>
'<code>nosubreq|NS</code>'
(not for internal
sub-requests)</dt><dd>
<p>This flag forces the rewriting engine to skip a
rewriting rule if the current request is an internal
sub-request. For instance, sub-requests occur internally
in Apache when <code class="module"><a href="/mod/mod_dir.html">mod_dir</a></code> tries to find out
information about possible directory default files
(<code>index.xxx</code> files). On sub-requests it is not
always useful, and can even cause errors, if
the complete set of rules are applied. Use this flag to
exclude some rules.</p>
<p>To decide whether or not to use this rule: if you
prefix URLs with CGI-scripts, to force them to be
processed by the CGI-script, it's likely that you
will run into problems (or significant overhead) on
sub-requests. In these cases, use this flag.</p>
</dd>
<dt>
'<code>proxy|P</code>' (force
proxy)</dt><dd>
This flag forces the substitution part to be internally
sent as a proxy request and immediately (rewrite
processing stops here) put through the <a href="mod_proxy.html">proxy module</a>. You must make
sure that the substitution string is a valid URI
(typically starting with
<code>http://</code><em>hostname</em>) which can be
handled by the Apache proxy module. If not, you will get an
error from the proxy module. Use this flag to achieve a
more powerful implementation of the <a href="mod_proxy.html#proxypass">ProxyPass</a> directive,
to map remote content into the namespace of the local
server.
<p>Note: <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> must be enabled in order
to use this flag.</p>
</dd>
<dt>
'<code>passthrough|PT</code>'
(pass through to next
handler)</dt><dd>
This flag forces the rewrite engine to set the
<code>uri</code> field of the internal
<code>request_rec</code> structure to the value of the
<code>filename</code> field. This flag is just a hack to
enable post-processing of the output of
<code>RewriteRule</code> directives, using
<code>Alias</code>, <code>ScriptAlias</code>,
<code>Redirect</code>, and other directives from
various URI-to-filename translators. For example, to rewrite
<code>/abc</code> to <code>/def</code> using
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>, and then
<code>/def</code> to <code>/ghi</code> using
<code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code>:
<div class="example"><p><code>
RewriteRule ^/abc(.*) /def$1 [PT]<br />
Alias /def /ghi
</code></p></div>
If you omit the <code>PT</code> flag,
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> will rewrite
<code>uri=/abc/...</code> to
<code>filename=/def/...</code> as a full API-compliant
URI-to-filename translator should do. Then
<code>mod_alias</code> will try to do a
URI-to-filename transition, which will fail.
<p>Note: <strong>You must use this flag if you want to
mix directives from different modules which allow
URL-to-filename translators</strong>. The typical example
is the use of <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> and
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
<p>The <code>PT</code> flag implies the <code>L</code> flag:
rewriting will be stopped in order to pass the request to
the next phase of processing.</p>
</dd>
<dt>'<code>qsappend|QSA</code>'
(query string
append)</dt><dd>
This flag forces the rewrite engine to append the query
string part of the substitution string to the existing query string,
instead of replacing it. Use this when you want to add more
data to the query string via a rewrite rule. This rule has no net effect
unless your substitution explicitly provides a new query string.</dd>
<dt>'<code>redirect|R</code>
[=<em>code</em>]' (force <a id="redirect" name="redirect">redirect</a>)</dt><dd>
<p>Prefix <em>Substitution</em> with
<code>http://thishost[:thisport]/</code> (which makes the
new URL a URI) to force a external redirection. If no
<em>code</em> is given, a HTTP response of 302 (MOVED
TEMPORARILY) will be returned. If you want to use other
response codes, simply specify the appropriate number or use
one of the following symbolic names: <code>temp</code>
(default), <code>permanent</code>,
<code>seeother</code>. Use this for rules to canonicalize
the URL and return it to the client - to translate
``<code>/~</code>'' into ``<code>/u/</code>'', or to always
append a slash to <code>/u/</code><em>user</em>, etc.<br />
<strong>Note:</strong> When you use this flag, make sure
that the substitution field is a valid URL! Otherwise, you
will be redirecting to an invalid location. Remember that
this flag on its own will only prepend
<code>http://thishost[:thisport]/</code> to the URL, and
rewriting will continue. Usually, you will want to stop
rewriting at this point, and redirect immediately. To stop
rewriting, you should add the 'L' flag.</p>
<p>While this is typically used for redirects, any valid status
code can be given here. If the status code is outside the redirect
range (300-399), then the <em>Substitution</em> string is dropped
and rewriting is stopped as if the <code>L</code> flag was
used.</p>
</dd>
<dt>'<code>skip|S</code>=<em>num</em>'
(skip next rule(s))</dt><dd>
This flag forces the rewriting engine to skip the next
<em>num</em> rules in sequence, if the current rule
matches. Use this to make pseudo if-then-else constructs:
The last rule of the then-clause becomes
<code>skip=N</code>, where N is the number of rules in the
else-clause. (This is <strong>not</strong> the same as the
'chain|C' flag!)</dd>
<dt>
'<code>type|T</code>=<em>MIME-type</em>'
(force MIME type)</dt><dd>
Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file to be
<em>MIME-type</em>. This can be used to
set up the content-type based on some conditions.
If used in per-directory context, use only <code>-</code> (dash)
as the substitution, otherwise the MIME-type set with this flag
is lost due to an internal re-processing.</dd>
</dl>
<div class="note"><h3>Home directory expansion</h3>
<p> When the substitution string begins with a string
resembling "/~user" (via explicit text or backreferences), mod_rewrite performs
home directory expansion independent of the presence or configuration
of <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>.</p>
<p> This expansion does not occur when the <em>PT</em>
flag is used on the <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
directive.</p>
</div>
<div class="note"><h3>Per-directory Rewrites</h3>
<p>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files. To enable the
rewrite engine for these files you need to set
"<code>RewriteEngine On</code>" <strong>and</strong>
"<code>Options FollowSymLinks</code>" must be enabled. If your
administrator has disabled override of <code>FollowSymLinks</code> for
a user's directory, then you cannot use the rewrite engine. This
restriction is required for security reasons.</p>
<p>When using the rewrite engine in <code>.htaccess</code> files the
per-directory prefix (which always is the same for a specific
directory) is automatically <em>removed</em> for the pattern matching
and automatically <em>added</em> after the substitution has been
done. This feature is essential for many sorts of rewriting; without
this, you would always have to match the parent directory, which is
not always possible. There is one exception: If a substitution string
starts with <code>http://</code>, then the directory prefix will
<strong>not</strong> be added, and an external redirect (or proxy
throughput, if using flag <strong>P</strong>) is forced. See the
<code class="directive"><a href="#rewritebase">RewriteBase</a></code> directive for
more information.</p>
<p>The rewrite engine may also be used in <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> sections with the same
prefix-matching rules as would be applied to <code>.htaccess</code>
files. It is usually simpler, however, to avoid the prefix substitution
complication by putting the rewrite rules in the main server or
virtual host context, rather than in a <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> section.</p>
<p>Although rewrite rules are syntactically permitted in <code class="directive"><a href="/mod/core.html#location">&lt;Location&gt;</a></code> and <code class="directive"><a href="/mod/core.html#files">&lt;Files&gt;</a></code> sections, this
should never be necessary and is unsupported.</p>
</div>
<p>Here are all possible substitution combinations and their
meanings:</p>
<p><strong>Inside per-server configuration
(<code>httpd.conf</code>)<br />
for request ``<code>GET
/somepath/pathinfo</code>'':</strong><br />
</p>
<div class="note"><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 invalid, not supported
^/somepath(.*) otherpath$1 [R] invalid, not supported
^/somepath(.*) otherpath$1 [P] invalid, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></div>
<p><strong>Inside per-directory configuration for
<code>/somepath</code><br />
(<code>/physical/path/to/somepath/.htacccess</code>, with
<code>RewriteBase /somepath</code>)<br />
for request ``<code>GET
/somepath/localpath/pathinfo</code>'':</strong><br />
</p>
<div class="note"><pre>
<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
via external redirection
^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
</pre></div>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>