mod_rewrite.html.en revision 790a477f6ce41161c4173c1e5080a1f569976a1e
97a9a944b5887e91042b019776c41d5dd74557aferikabele<?xml version="1.0" encoding="ISO-8859-1"?>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
97a9a944b5887e91042b019776c41d5dd74557aferikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki This file is generated from xml source: DO NOT EDIT
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd -->
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<title>mod_rewrite - Apache HTTP Server</title>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<body>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="page-header">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz<p class="apache">Apache HTTP Server Version 2.3</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<img alt="" src="/images/feather.gif" /></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="path">
4b5981e276e93df97c34e4da05ca5cf8bbd937dand<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>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="page-content">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="preamble"><h1>Apache Module mod_rewrite</h1>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="toplang">
7dc5a2d4a0c77f5bf5a95de92d68e43de7d8117anilgun<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
7dc5a2d4a0c77f5bf5a95de92d68e43de7d8117anilgun<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndURLs on the fly</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr></table>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h3>Summary</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p>The <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> module uses a rule-based rewriting
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin engine, based on a regular-expression parser, to rewrite requested URLs on
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin the fly. By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> maps a URL to a filesystem
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin path. However, it can also be used to redirect one URL to another URL, or
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin to invoke an internal proxy fetch.</p>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> provides a flexible and powerful way to
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin manipulate URLs using an unlimited number of rules. Each rule can have an
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin unlimited number of attached rule conditions, to allow you to rewrite URL
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin based on server variables, environment variables, HTTP headers, or time
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin stamps.</p>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> operates on the full URL path, including the
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin path-info section. A rewrite rule can be invoked in
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin by a rewrite rule can include a query string, or can lead to internal
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin sub-processing, external request redirection, or internal proxy
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin throughput.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <p>Further details, discussion, and examples, are provided in the
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div id="quickview"><h3 class="directives">Directives</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<ul id="toc">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritelog">RewriteLog</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteloglevel">RewriteLogLevel</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</ul>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteBase</code> directive explicitly
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener sets the base URL-path (not filesystem directory path!) for per-directory rewrites.
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin When you use a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin in a <code>.htaccess</code> file, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> strips off
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin the local directory prefix before processing, then rewrites the rest of
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin the URL. When the rewrite is completed, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin automatically adds the local directory prefix back on to the path.</p>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <p>This directive is <em>required</em> for per-directory rewrites whose context
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener is a directory made available via the <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener directive.</p>
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <p>If your URL path does not exist verbatim on the filesystem,
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener or isn't directly under your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>,
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin you must use <code class="directive">RewriteBase</code> in every
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener <code>.htaccess</code> file where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.</p>
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin <p>The example below demonstrates how to map
fa0f379e3845907d7c1087d885169e302239bdbbnd http://example.com/myapp/index.html to
fa0f379e3845907d7c1087d885169e302239bdbbnd /home/www/example/newsite.html, in a <code>.htaccess</code> file. This
fa0f379e3845907d7c1087d885169e302239bdbbnd assumes that the content available at
fa0f379e3845907d7c1087d885169e302239bdbbnd http://example.com/ is on disk at /home/www/example/</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteEngine On
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovener# The URL-path used to get to this context, not the filesystem path
25d988d92af8cf0d997aa1ebbc7cb11daa14d0becovenerRewriteBase /myapp/
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirinRewriteRule ^index\.html$ newsite.html
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <em>TestString</em> <em>CondPattern</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>The <code class="directive">RewriteCond</code> directive defines a
fa0f379e3845907d7c1087d885169e302239bdbbnd rule condition. One or more <code class="directive">RewriteCond</code>
fa0f379e3845907d7c1087d885169e302239bdbbnd can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
fa0f379e3845907d7c1087d885169e302239bdbbnd directive. The following rule is then only used if both
fa0f379e3845907d7c1087d885169e302239bdbbnd the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p><em>TestString</em> is a string which can contain the
fa0f379e3845907d7c1087d885169e302239bdbbnd following expanded constructs in addition to plain text:</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteRule backreferences</strong>: These are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem backreferences of the form <strong><code>$N</code></strong>
b115299831a7b4bbec58a88d708d8536e1ecd50csf (0 &lt;= N &lt;= 9). $1 to $9 provide access to the grouped
fa0f379e3845907d7c1087d885169e302239bdbbnd parts (in parentheses) of the pattern, from the
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>RewriteRule</code> which is subject to the current
b115299831a7b4bbec58a88d708d8536e1ecd50csf set of <code>RewriteCond</code> conditions. $0 provides
b115299831a7b4bbec58a88d708d8536e1ecd50csf access to the whole string matched by that pattern.
fa0f379e3845907d7c1087d885169e302239bdbbnd </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteCond backreferences</strong>: These are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem backreferences of the form <strong><code>%N</code></strong>
b115299831a7b4bbec58a88d708d8536e1ecd50csf (0 &lt;= N &lt;= 9). %1 to %9 provide access to the grouped
fa0f379e3845907d7c1087d885169e302239bdbbnd parts (again, in parentheses) of the pattern, from the last matched
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>RewriteCond</code> in the current set
b115299831a7b4bbec58a88d708d8536e1ecd50csf of conditions. %0 provides access to the whole string matched by
b115299831a7b4bbec58a88d708d8536e1ecd50csf that pattern.
fa0f379e3845907d7c1087d885169e302239bdbbnd </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>RewriteMap expansions</strong>: These are
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem expansions of the form <strong><code>${mapname:key|default}</code></strong>.
fa0f379e3845907d7c1087d885169e302239bdbbnd See <a href="#mapfunc">the documentation for
fa0f379e3845907d7c1087d885169e302239bdbbnd RewriteMap</a> for more details.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <strong>Server-Variables</strong>: These are variables of
81785f72c9d133aef57ad6b02f248345d90239aapoirier the form
fa0f379e3845907d7c1087d885169e302239bdbbnd <strong><code>%{</code> <em>NAME_OF_VARIABLE</em>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>}</code></strong>
fa0f379e3845907d7c1087d885169e302239bdbbnd where <em>NAME_OF_VARIABLE</em> can be a string taken
fa0f379e3845907d7c1087d885169e302239bdbbnd from the following list:
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <table>
c6a2d6fa44f8698851dec5051ee3782c2913605fnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <th>HTTP headers:</th> <th>connection &amp; request:</th> <th />
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <td>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi HTTP_USER_AGENT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_REFERER<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_COOKIE<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_FORWARDED<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_HOST<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_PROXY_CONNECTION<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele HTTP_ACCEPT<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_ADDR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_HOST<br />
74a6de79356cd15d2e47065087785e36dd65aa41nd REMOTE_PORT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_USER<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REMOTE_IDENT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_METHOD<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SCRIPT_FILENAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele PATH_INFO<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele QUERY_STRING<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele AUTH_TYPE<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <td />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <tr>
53d2fd50ff45e7c568f0588c742a5ef9edf8e275rbowen <th>server internals:</th> <th>date and time:</th> <th>specials:</th>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </tr>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <tr>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <td>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi DOCUMENT_ROOT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_ADMIN<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_NAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_ADDR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_PORT<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_PROTOCOL<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele SERVER_SOFTWARE<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_YEAR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_MON<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_DAY<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_HOUR<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_MIN<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_SEC<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME_WDAY<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele TIME<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <td>
97a9a944b5887e91042b019776c41d5dd74557aferikabele API_VERSION<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele THE_REQUEST<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_URI<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele REQUEST_FILENAME<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele IS_SUBREQ<br />
fb82af0f0cd7b58eef19c54b086131b7e1e1e749madhum HTTPS<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </td>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </table>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>These variables all
fa0f379e3845907d7c1087d885169e302239bdbbnd correspond to the similarly named HTTP
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen MIME-headers, C variables of the Apache HTTP Server or
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>struct tm</code> fields of the Unix system.
fa0f379e3845907d7c1087d885169e302239bdbbnd Most are documented elsewhere in the Manual or in
fa0f379e3845907d7c1087d885169e302239bdbbnd the CGI specification. Those that are special to
fa0f379e3845907d7c1087d885169e302239bdbbnd mod_rewrite include those below.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <div class="note">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dl>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>IS_SUBREQ</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>Will contain the text "true" if the request
fa0f379e3845907d7c1087d885169e302239bdbbnd currently being processed is a sub-request,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "false" otherwise. Sub-requests may be generated
06ba4a61654b3763ad65f52283832ebf058fdf1cslive by modules that need to resolve additional files
06ba4a61654b3763ad65f52283832ebf058fdf1cslive or URIs in order to complete their tasks.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>API_VERSION</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <dd>This is the version of the Apache httpd module API
fa0f379e3845907d7c1087d885169e302239bdbbnd (the internal interface between server and
fa0f379e3845907d7c1087d885169e302239bdbbnd module) in the current httpd build, as defined in
fa0f379e3845907d7c1087d885169e302239bdbbnd include/ap_mmn.h. The module API version
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen corresponds to the version of Apache httpd in use (in
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen the release version of Apache httpd 1.3.14, for
fa0f379e3845907d7c1087d885169e302239bdbbnd instance, it is 19990320:10), but is mainly of
fa0f379e3845907d7c1087d885169e302239bdbbnd interest to module authors.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>THE_REQUEST</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The full HTTP request line sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser to the server (e.g., "<code>GET
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /index.html HTTP/1.1</code>"). This does not
06ba4a61654b3763ad65f52283832ebf058fdf1cslive include any additional headers sent by the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive browser.</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>REQUEST_URI</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dd>The resource requested in the HTTP request
fa0f379e3845907d7c1087d885169e302239bdbbnd line. (In the example above, this would be
fa0f379e3845907d7c1087d885169e302239bdbbnd "/index.html".)</dd>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <dt><code>REQUEST_FILENAME</code></dt>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>The full local filesystem path to the file or
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener script matching the request, if this has already
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener been determined by the server at the time
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener <code>REQUEST_FILENAME</code> is referenced. Otherwise,
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener such as when used in virtual host context, the same
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener value as <code>REQUEST_URI</code>.</dd>
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <dt><code>HTTPS</code></dt>
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <dd>Will contain the text "on" if the connection is
fa0f379e3845907d7c1087d885169e302239bdbbnd using SSL/TLS, or "off" otherwise. (This variable
fa0f379e3845907d7c1087d885169e302239bdbbnd can be safely used regardless of whether or not
fa0f379e3845907d7c1087d885169e302239bdbbnd <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded).</dd>
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </dl>
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
fa0f379e3845907d7c1087d885169e302239bdbbnd </li>
fa0f379e3845907d7c1087d885169e302239bdbbnd </ul>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>Other things you should be aware of:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fa0f379e3845907d7c1087d885169e302239bdbbnd <ol>
fa0f379e3845907d7c1087d885169e302239bdbbnd <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>The variables SCRIPT_FILENAME and REQUEST_FILENAME
fa0f379e3845907d7c1087d885169e302239bdbbnd contain the same value - the value of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>filename</code> field of the internal
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <code>request_rec</code> structure of the Apache HTTP Server.
fa0f379e3845907d7c1087d885169e302239bdbbnd The first name is the commonly known CGI variable name
fa0f379e3845907d7c1087d885169e302239bdbbnd while the second is the appropriate counterpart of
fa0f379e3845907d7c1087d885169e302239bdbbnd REQUEST_URI (which contains the value of the
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>uri</code> field of <code>request_rec</code>).</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If a substitution occurred and the rewriting continues,
fa0f379e3845907d7c1087d885169e302239bdbbnd the value of both variables will be updated accordingly.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If used in per-server context (<em>i.e.</em>, before the
fa0f379e3845907d7c1087d885169e302239bdbbnd request is mapped to the filesystem) SCRIPT_FILENAME and
fa0f379e3845907d7c1087d885169e302239bdbbnd REQUEST_FILENAME cannot contain the full local filesystem
fa0f379e3845907d7c1087d885169e302239bdbbnd path since the path is unknown at this stage of processing.
fa0f379e3845907d7c1087d885169e302239bdbbnd Both variables will initially contain the value of REQUEST_URI
fa0f379e3845907d7c1087d885169e302239bdbbnd in that case. In order to obtain the full local filesystem
fa0f379e3845907d7c1087d885169e302239bdbbnd path of the request in per-server context, use an URL-based
a4d04b8c74044c58bd4182028a1408d936c95951covener look-ahead <code>%{LA-U:REQUEST_FILENAME}</code> to determine
fa0f379e3845907d7c1087d885169e302239bdbbnd the final value of REQUEST_FILENAME.</p></li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fa0f379e3845907d7c1087d885169e302239bdbbnd <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{ENV:variable}</code>, where <em>variable</em> can be
fa0f379e3845907d7c1087d885169e302239bdbbnd any environment variable, is also available.
fa0f379e3845907d7c1087d885169e302239bdbbnd This is looked-up via internal
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen Apache httpd structures and (if not found there) via
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <code>getenv()</code> from the Apache httpd server process.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{SSL:variable}</code>, where <em>variable</em> is the
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd name of an <a href="mod_ssl.html#envvars">SSL environment
fa0f379e3845907d7c1087d885169e302239bdbbnd variable</a>, can be used whether or not
fa0f379e3845907d7c1087d885169e302239bdbbnd <code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded, but will always expand to
fa0f379e3845907d7c1087d885169e302239bdbbnd the empty string if it is not. Example:
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{SSL:SSL_CIPHER_USEKEYSIZE}</code> may expand to
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>128</code>.</li>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{HTTP:header}</code>, where <em>header</em> can be
fa0f379e3845907d7c1087d885169e302239bdbbnd any HTTP MIME-header name, can always be used to obtain the
fa0f379e3845907d7c1087d885169e302239bdbbnd value of a header sent in the HTTP request.
fa0f379e3845907d7c1087d885169e302239bdbbnd Example: <code>%{HTTP:Proxy-Connection}</code> is
fa0f379e3845907d7c1087d885169e302239bdbbnd the value of the HTTP header
fa0f379e3845907d7c1087d885169e302239bdbbnd ``<code>Proxy-Connection:</code>''.
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>If a HTTP header is used in a condition this header is added to
fa0f379e3845907d7c1087d885169e302239bdbbnd the Vary header of the response in case the condition evaluates to
fa0f379e3845907d7c1087d885169e302239bdbbnd to true for the request. It is <strong>not</strong> added if the
fa0f379e3845907d7c1087d885169e302239bdbbnd condition evaluates to false for the request. Adding the HTTP header
fa0f379e3845907d7c1087d885169e302239bdbbnd to the Vary header of the response is needed for proper caching.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>It has to be kept in mind that conditions follow a short circuit
fa0f379e3845907d7c1087d885169e302239bdbbnd logic in the case of the '<strong><code>ornext|OR</code></strong>' flag
fa0f379e3845907d7c1087d885169e302239bdbbnd so that certain conditions might not be evaluated at all.</p></li>
fa0f379e3845907d7c1087d885169e302239bdbbnd
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{LA-U:variable}</code> can be used for look-aheads which perform
fa0f379e3845907d7c1087d885169e302239bdbbnd an internal (URL-based) sub-request to determine the final
fa0f379e3845907d7c1087d885169e302239bdbbnd value of <em>variable</em>. This can be used to access
fa0f379e3845907d7c1087d885169e302239bdbbnd variable for rewriting which is not available at the current
fa0f379e3845907d7c1087d885169e302239bdbbnd stage, but will be set in a later phase.
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>For instance, to rewrite according to the
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>REMOTE_USER</code> variable from within the
fa0f379e3845907d7c1087d885169e302239bdbbnd per-server context (<code>httpd.conf</code> file) you must
fa0f379e3845907d7c1087d885169e302239bdbbnd use <code>%{LA-U:REMOTE_USER}</code> - this
fa0f379e3845907d7c1087d885169e302239bdbbnd variable is set by the authorization phases, which come
fa0f379e3845907d7c1087d885169e302239bdbbnd <em>after</em> the URL translation phase (during which mod_rewrite
fa0f379e3845907d7c1087d885169e302239bdbbnd operates).</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>On the other hand, because mod_rewrite implements
fa0f379e3845907d7c1087d885169e302239bdbbnd its per-directory context (<code>.htaccess</code> file) via
fa0f379e3845907d7c1087d885169e302239bdbbnd the Fixup phase of the API and because the authorization
fa0f379e3845907d7c1087d885169e302239bdbbnd phases come <em>before</em> this phase, you just can use
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{REMOTE_USER}</code> in that context.</p></li>
fa0f379e3845907d7c1087d885169e302239bdbbnd
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>%{LA-F:variable}</code> can be used to perform an internal
fa0f379e3845907d7c1087d885169e302239bdbbnd (filename-based) sub-request, to determine the final value
fa0f379e3845907d7c1087d885169e302239bdbbnd of <em>variable</em>. Most of the time, this is the same as
fa0f379e3845907d7c1087d885169e302239bdbbnd LA-U above.</li>
fa0f379e3845907d7c1087d885169e302239bdbbnd </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><em>CondPattern</em> is the condition pattern,
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem a regular expression which is applied to the
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem current instance of the <em>TestString</em>.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>TestString</em> is first evaluated, before being matched against
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Remember:</strong> <em>CondPattern</em> is a
630c456b6461158be6cc5c5483735e27b13b4ad5nd <em>perl compatible regular expression</em> with some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive additions:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>You can prefix the pattern string with a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<code>!</code>' character (exclamation mark) to specify a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>non</strong>-matching pattern.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive There are some special variants of <em>CondPatterns</em>.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Instead of real regular expression strings you can also
81785f72c9d133aef57ad6b02f248345d90239aapoirier use one of the following:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
81785f72c9d133aef57ad6b02f248345d90239aapoirier <li>'<strong>&lt;CondPattern</strong>' (lexicographically
5ae30adbe59946de742ab0cd6be3b7457471a698takashi precedes)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>CondPattern</em> as a plain string and
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem compares it lexicographically to <em>TestString</em>. True if
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>TestString</em> lexicographically precedes
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>&gt;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 <em>TestString</em> lexicographically follows
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>CondPattern</em>.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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 <em>TestString</em> is lexicographically equal to
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>CondPattern</em> (the two strings are exactly
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem equal, character for character). If <em>CondPattern</em>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem is <code>""</code> (two quotation marks) this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive compares <em>TestString</em> to the empty string.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-d</strong>' (is
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>d</strong>irectory)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a directory.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-f</strong>' (is regular
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>f</strong>ile)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a regular file.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>-s</strong>' (is regular file, with
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>s</strong>ize)<br />
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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong>-l</strong>' (is symbolic
97a9a944b5887e91042b019776c41d5dd74557aferikabele <strong>l</strong>ink)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Treats the <em>TestString</em> as a pathname and tests
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem whether or not it exists, and is a symbolic link.</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
4e3cdb85620921a8a120fe22edbccae708f4f34end <li>'<strong>-x</strong>' (has e<strong>x</strong>ecutable
4e3cdb85620921a8a120fe22edbccae708f4f34end permissions)<br />
4e3cdb85620921a8a120fe22edbccae708f4f34end Treats the <em>TestString</em> as a pathname and tests
81785f72c9d133aef57ad6b02f248345d90239aapoirier whether or not it exists, and has executable permissions.
81785f72c9d133aef57ad6b02f248345d90239aapoirier These permissions are determined according to
5ae30adbe59946de742ab0cd6be3b7457471a698takashi the underlying OS.</li>
4e3cdb85620921a8a120fe22edbccae708f4f34end
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>-F</strong>' (is existing file, via
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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>'<strong>-U</strong>' (is existing URL, via
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
81785f72c9d133aef57ad6b02f248345d90239aapoirier subrequest to do the check, so use it with care -
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem it can impact your server's performance!</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem<div class="note"><h3>Note:</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive All of these tests can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive also be prefixed by an exclamation mark ('!') to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive negate their meaning.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <li>You can also set special flags for
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <em>CondPattern</em> by appending
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:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ul>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>'<strong><code>nocase|NC</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>n</strong>o <strong>c</strong>ase)<br />
81785f72c9d133aef57ad6b02f248345d90239aapoirier This makes the test case-insensitive - differences
5ae30adbe59946de742ab0cd6be3b7457471a698takashi 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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive '<strong><code>ornext|OR</code></strong>'
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<strong>or</strong> next condition)<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Use this to combine rule conditions with a local OR
81785f72c9d133aef57ad6b02f248345d90239aapoirier instead of the implicit AND. Typical example:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host1.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host2.* [OR]
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{REMOTE_HOST} ^host3.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ...some special stuff for any of these hosts...
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem Without this flag you would have to write the condition/rule
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem pair three times.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </li>
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl <li>'<strong><code>novary|NV</code></strong>'
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl (<strong>n</strong>o <strong>v</strong>ary)<br />
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.
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl </li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ul>
22d5d84393d960a2027f472036f3fee15d7dbce9nd </li>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem </ol>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Example:</strong></p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>To rewrite the Homepage of a site according to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ``<code>User-Agent:</code>'' header of the request, you can
06ba4a61654b3763ad65f52283832ebf058fdf1cslive use the following: </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.max.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteCond %{HTTP_USER_AGENT} ^Lynx.*
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.min.html [L]
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteRule ^/$ /homepage.std.html [L]
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
81785f72c9d133aef57ad6b02f248345d90239aapoirier <p>Explanation: If you use a browser which identifies itself
5ae30adbe59946de742ab0cd6be3b7457471a698takashi as 'Mozilla' (including Netscape Navigator, Mozilla etc), then you
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem get the max homepage (which could include frames, or other special
5ae30adbe59946de742ab0cd6be3b7457471a698takashi features).
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem If you use the Lynx browser (which is terminal-based), then
81785f72c9d133aef57ad6b02f248345d90239aapoirier you get the min homepage (which could be a version designed for
5ae30adbe59946de742ab0cd6be3b7457471a698takashi easy, text-only browsing).
5ae30adbe59946de742ab0cd6be3b7457471a698takashi If neither of these conditions apply (you use any other browser,
5ae30adbe59946de742ab0cd6be3b7457471a698takashi or your browser identifies itself as something non-standard), you get
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem the std (standard) homepage.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
81785f72c9d133aef57ad6b02f248345d90239aapoirier</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteEngine</code> directive enables or
06ba4a61654b3763ad65f52283832ebf058fdf1cslive disables the runtime rewriting engine. If it is set to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>off</code> this module does no runtime processing at
06ba4a61654b3763ad65f52283832ebf058fdf1cslive all. It does not even update the <code>SCRIPT_URx</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive environment variables.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Use this directive to disable the module instead of
97a9a944b5887e91042b019776c41d5dd74557aferikabele commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <p><code class="directive">RewriteMap</code> directives of the type <code>prg</code>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener are not started during server initialization if they're defined in a
fc9f416faa11879811f17d6efadedbf81cfd52a1covener context that does not have <code class="directive">RewriteEngine</code> set to
fc9f416faa11879811f17d6efadedbf81cfd52a1covener <code>on</code></p>
fc9f416faa11879811f17d6efadedbf81cfd52a1covener
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteLog" id="RewriteLog">RewriteLog</a> <a name="rewritelog" id="rewritelog">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the name of the file used for logging rewrite engine
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndprocessing</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLog <em>file-path</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteLog</code> directive sets the name
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of the file to which the server logs any rewriting actions it
06ba4a61654b3763ad65f52283832ebf058fdf1cslive performs. If the name does not begin with a slash
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ('<code>/</code>') then it is assumed to be relative to the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Server Root</em>. The directive should occur only once per
06ba4a61654b3763ad65f52283832ebf058fdf1cslive server config.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"> To disable the logging of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rewriting actions it is not recommended to set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Filename</em> to <code>/dev/null</code>, because
06ba4a61654b3763ad65f52283832ebf058fdf1cslive although the rewriting engine does not then output to a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive logfile it still creates the logfile output internally.
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong>This will slow down the server with no advantage
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to the administrator!</strong> To disable logging either
06ba4a61654b3763ad65f52283832ebf058fdf1cslive remove or comment out the <code class="directive">RewriteLog</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive or use <code>RewriteLogLevel 0</code>!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><h3>Security</h3>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowenSee the <a href="/misc/security_tips.html">Apache HTTP Server 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.
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLog "/usr/local/var/apache/logs/rewrite.log"
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteLogLevel" id="RewriteLogLevel">RewriteLogLevel</a> <a name="rewriteloglevel" id="rewriteloglevel">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the verbosity of the log file used by the rewrite
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4ndengine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteLogLevel <em>Level</em></code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteLogLevel 0</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteLogLevel</code> directive sets the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive verbosity level of the rewriting logfile. The default level 0
06ba4a61654b3763ad65f52283832ebf058fdf1cslive means no logging, while 9 or more means that practically all
06ba4a61654b3763ad65f52283832ebf058fdf1cslive actions are logged.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>To disable the logging of rewriting actions simply set
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Level</em> to 0. This disables all rewrite action
06ba4a61654b3763ad65f52283832ebf058fdf1cslive logs.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"> Using a high value for
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <em>Level</em> will slow down your Apache HTTP Server
06ba4a61654b3763ad65f52283832ebf058fdf1cslive dramatically! Use the rewriting logfile at a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Level</em> greater than 2 only for debugging!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="example"><h3>Example</h3><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1csliveRewriteLogLevel 3
97a9a944b5887e91042b019776c41d5dd74557aferikabele</code></p></div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</code></td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowenApache HTTP Server 2.0.41 and later</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteMap</code> directive defines a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>Rewriting Map</em> which can be used inside rule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive substitution strings by the mapping-functions to
06ba4a61654b3763ad65f52283832ebf058fdf1cslive insert/substitute fields through a key lookup. The source of
06ba4a61654b3763ad65f52283832ebf058fdf1cslive this lookup can be of various types.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the name of the map and will be used to specify a
06ba4a61654b3763ad65f52283832ebf058fdf1cslive mapping-function for the substitution strings of a rewriting
06ba4a61654b3763ad65f52283832ebf058fdf1cslive rule via one of the following constructs:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <strong><code>${</code> <em>MapName</em> <code>:</code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele <em>LookupKey</em> <code>}</code><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>${</code> <em>MapName</em> <code>:</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>LookupKey</em> <code>|</code> <em>DefaultValue</em>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>}</code></strong>
97a9a944b5887e91042b019776c41d5dd74557aferikabele </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if no <em>DefaultValue</em> was specified.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <p>For example, you might define a
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <code class="directive">RewriteMap</code> as:</p>
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <div class="example"><p><code>
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen RewriteMap examplemap txt:/path/to/file/map.txt
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen </code></p></div>
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <p>You would then be able to use this map in a
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <code class="directive">RewriteRule</code> as follows:</p>
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen <div class="example"><p><code>
8ac3ff7008df949c096f9cd8f769c7893594f61fnd RewriteRule ^/ex/(.*) ${examplemap:$1}
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen </code></p></div>
0ccb6ee166750359937ae35d59c0beb54f8fd228rbowen
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The following combinations for <em>MapType</em> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <em>MapSource</em> can be used:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dl>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>txt</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>A plain text file containing space-separated key-value
790a477f6ce41161c4173c1e5080a1f569976a1erbowen pairs, one per line. (<a href="/rewrite/rewritemap.html#txt">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>rnd</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Randomly selects an entry from a plain text file (<a href="/rewrite/rewritemap.html#rnd">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>dbm</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Looks up an entry in a dbm file containing name, value
0a3142725875ea286597e083547d34d98f8c1f2drbowen pairs. Hash is constructed from a plain text file format using
0a3142725875ea286597e083547d34d98f8c1f2drbowen the <code><a href="/programs/httxt2dbm.html">httxt2dbm</a></code>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen utility. (<a href="/rewrite/rewritemap.html#dbm">Details ...</a>)</dd>
0a3142725875ea286597e083547d34d98f8c1f2drbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>int</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>One of the four available internal functions provided by
0a3142725875ea286597e083547d34d98f8c1f2drbowen <code>RewriteMap</code>: toupper, tolower, escape or
790a477f6ce41161c4173c1e5080a1f569976a1erbowen unescape. (<a href="/rewrite/rewritemap.html#int">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>prg</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>Calls an external program or script to process the
790a477f6ce41161c4173c1e5080a1f569976a1erbowen rewriting. (<a href="/rewrite/rewritemap.html#prg">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dt>dbd or fastdbd</dt>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen <dd>A SQL SELECT statement to be performed to look up the
790a477f6ce41161c4173c1e5080a1f569976a1erbowen rewrite target. (<a href="/rewrite/rewritemap.html#dbd">Details ...</a>)</dd>
790a477f6ce41161c4173c1e5080a1f569976a1erbowen </dl>
0a3142725875ea286597e083547d34d98f8c1f2drbowen
0a3142725875ea286597e083547d34d98f8c1f2drbowen <p>Further details, and numerous examples, may be found in the <a href="/rewrite/rewritemap.html">RewriteMap HowTo</a></p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
0203b896e484dfb877111aceffb812401d0f216and<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></code></td></tr>
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
0203b896e484dfb877111aceffb812401d0f216andlater</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteOptions</code> directive sets some
06ba4a61654b3763ad65f52283832ebf058fdf1cslive special options for the current per-server or per-directory
81785f72c9d133aef57ad6b02f248345d90239aapoirier configuration. The <em>Option</em> string can currently
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem only be one of the following:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
0203b896e484dfb877111aceffb812401d0f216and <dl>
0203b896e484dfb877111aceffb812401d0f216and <dt><code>inherit</code></dt>
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
a4d04b8c74044c58bd4182028a1408d936c95951covener <code>.htaccess</code> configuration or
a4d04b8c74044c58bd4182028a1408d936c95951covener <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code>
a4d04b8c74044c58bd4182028a1408d936c95951covener sections are inherited. The inherited rules are virtually copied
a4d04b8c74044c58bd4182028a1408d936c95951covener to the section where this directive is being used. If used in
a4d04b8c74044c58bd4182028a1408d936c95951covener combination with local rules, the inherited rules are copied behind
a4d04b8c74044c58bd4182028a1408d936c95951covener the local rules. The position of this directive - below or above
a4d04b8c74044c58bd4182028a1408d936c95951covener of local rules - has no influence on this behavior. If local
a4d04b8c74044c58bd4182028a1408d936c95951covener rules forced the rewriting to stop, the inherited rules won't
a4d04b8c74044c58bd4182028a1408d936c95951covener be processed.</dd>
0203b896e484dfb877111aceffb812401d0f216and </dl>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<table class="directive">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteRule
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>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</table>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The <code class="directive">RewriteRule</code> directive is the real
81785f72c9d133aef57ad6b02f248345d90239aapoirier 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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
630c456b6461158be6cc5c5483735e27b13b4ad5nd <p><a id="patterns" name="patterns"><em>Pattern</em></a> is
630c456b6461158be6cc5c5483735e27b13b4ad5nd a perl compatible <a id="regexp" name="regexp">regular
a4d04b8c74044c58bd4182028a1408d936c95951covener expression</a>. On the first RewriteRule it is applied to the (%-encoded)
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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
96147932f199be4ad038778e702c13a2f79051c0slive<div class="note"><h3>What is matched?</h3>
96147932f199be4ad038778e702c13a2f79051c0slive <p>The <em>Pattern</em> will initially be matched against the part of the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener URL after the hostname and port, and before the query string.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <p>When the RewriteRule appears in per-directory (htaccess) context, the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <em>Pattern</em> is matched against what remains of the URL after removing
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen the prefix that lead Apache httpd to the current rules (see the
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <code class="directive"><a href="#rewritebase">RewriteBase</a></code>). The removed prefix
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener always ends with a slash, meaning the matching occurs against a string which
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener never has a leading slash. A <em>Pattern</em> with <code>^/</code> never
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener matches in per-directory context.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <p>If you wish 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
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener <code>%{QUERY_STRING}</code> variables respectively. If you wish to
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener match against the full URL-path in a per-directory (htaccess) RewriteRule,
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener use the <code>%{REQUEST_URI}</code> variable.</p>
e619b7228ac42d9c70d6a5f02d808b0d2880080ccovener
96147932f199be4ad038778e702c13a2f79051c0slive</div>
96147932f199be4ad038778e702c13a2f79051c0slive
70f2730533c8592263435354e66d9dbaf4d6361bslive <p>For some hints on <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
70f2730533c8592263435354e66d9dbaf4d6361bslive expressions</a>, see
1093a264c81aa1041581ab059905fb8f7cdfc5e2rbowen the <a href="/rewrite/intro.html#regex">mod_rewrite
70f2730533c8592263435354e66d9dbaf4d6361bslive Introduction</a>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <p>In mod_rewrite, the NOT character
81785f72c9d133aef57ad6b02f248345d90239aapoirier ('<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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem<div class="note"><h3>Note</h3>
81785f72c9d133aef57ad6b02f248345d90239aapoirierWhen using the NOT character to negate a pattern, you cannot include
81785f72c9d133aef57ad6b02f248345d90239aapoiriergrouped wildcard parts in that pattern. This is because, when the
81785f72c9d133aef57ad6b02f248345d90239aapoirierpattern 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!
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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 be a:</p>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dl>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dt>file-system path</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dd>Designates the location on the file-system of the resource
96147932f199be4ad038778e702c13a2f79051c0slive to be delivered to the client.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
81785f72c9d133aef57ad6b02f248345d90239aapoirier <dt>URL-path</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
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
e00def5e805da9a73b72ad25dac664f0c8c36c2end or a URL-path by checking to see if the first segment of the
96147932f199be4ad038778e702c13a2f79051c0slive path exists at the root of the file-system. For example, if
96147932f199be4ad038778e702c13a2f79051c0slive you specify a <em>Substitution</em> string of
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 resulting URL-path, use the <code>[PT]</code> flag as
96147932f199be4ad038778e702c13a2f79051c0slive described below.</dd>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <dt>Absolute URL</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
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
96147932f199be4ad038778e702c13a2f79051c0slive <dt><code>-</code> (dash)</dt>
96147932f199be4ad038778e702c13a2f79051c0slive
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
96147932f199be4ad038778e702c13a2f79051c0slive </dl>
96147932f199be4ad038778e702c13a2f79051c0slive
96147932f199be4ad038778e702c13a2f79051c0slive <p>In addition to plain text, the <em>Substition</em> string can include</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <ol>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>back-references (<code>$N</code>) to the RewriteRule
06ba4a61654b3763ad65f52283832ebf058fdf1cslive pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <li>back-references (<code>%N</code>) to the last matched
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteCond pattern</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li>server-variables as in rule condition test-strings
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>%{VARNAME}</code>)</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <li><a href="#mapfunc">mapping-function</a> calls
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (<code>${mapname:key|default}</code>)</li>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </ol>
96147932f199be4ad038778e702c13a2f79051c0slive
81785f72c9d133aef57ad6b02f248345d90239aapoirier <p>Back-references are identifiers of the form
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <code>$</code><strong>N</strong>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<strong>N</strong>=0..9), which will be replaced
06ba4a61654b3763ad65f52283832ebf058fdf1cslive by the contents of the <strong>N</strong>th group of the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive matched <em>Pattern</em>. The server-variables are the same
06ba4a61654b3763ad65f52283832ebf058fdf1cslive as for the <em>TestString</em> of a <code>RewriteCond</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive. The mapping-functions come from the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>RewriteMap</code> directive and are explained there.
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem These three types of variables are expanded in the order above.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>As already mentioned, all rewrite rules are
81785f72c9d133aef57ad6b02f248345d90239aapoirier 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
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code><strong>L</strong></code> flag.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
96147932f199be4ad038778e702c13a2f79051c0slive <div class="note"><h3>Modifying the Query String</h3>
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
81785f72c9d133aef57ad6b02f248345d90239aapoirier <code>[QSA]</code> flag.</p>
96147932f199be4ad038778e702c13a2f79051c0slive </div>
70373b9ee042e7b3be82eee14b17f510fffdacc9slive
81785f72c9d133aef57ad6b02f248345d90239aapoirier <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>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive as the third argument to the <code>RewriteRule</code>
81785f72c9d133aef57ad6b02f248345d90239aapoirier directive. <em>Flags</em> is a comma-separated list, surround by square
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen brackets, of any of the flags in the following table. More
545fa9d9188f1ae00e785e784f23e1f0a62b7c25sf details, and examples, for each flag, are available in the <a href="/rewrite/flags.html">Rewrite Flags document</a>.</p>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <table>
545fa9d9188f1ae00e785e784f23e1f0a62b7c25sf <tr><th>Flag and syntax</th>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <th>Function</th>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>B</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Escape non-alphanumeric characters <em>before</em> applying
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen the transformation. <em><a href="/rewrite/flags.html#flag_b">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>chain|C</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Rule is chained to the following rule. If the rule fails,
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen the rule(s) chained to it will be skipped. <em><a href="/rewrite/flags.html#flag_c">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>cookie|CO=<em>NAME</em>:<em>VAL</em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Sets a cookie in the client browser. Full syntax is:
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen CO=<em>NAME</em>:<em>VAL</em>[:<em>domain</em>[:<em>lifetime</em>[:<em>path</em>[:<em>secure</em>[:<em>httponly</em>]]]]] <em><a href="/rewrite/flags.html#flag_co">details ...</a></em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>discardpathinfo|DPI</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes the PATH_INFO portion of the rewritten URI to be
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen discarded. <em><a href="/rewrite/flags.html#flag_dpi">details
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>env|E=<em>VAR</em>:<em>VAL</em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes an environment variable <em>VAR</em> to be set to the
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen value <em>VAL</em>. <em><a href="/rewrite/flags.html#flag_e">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>forbidden|F</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Returns a 403 FORBIDDEN response to the client browser.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em><a href="/rewrite/flags.html#flag_f">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>gone|G</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Returns a 410 GONE response to the client browser. <em><a href="/rewrite/flags.html#flag_g">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Handler|H=<em>Content-handler</em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes the resulting URI to be sent to the specified
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em>Content-handler</em> for processing. <em><a href="/rewrite/flags.html#flag_h">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>last|L</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Stop the rewriting process immediately and don't apply any
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen more rules. Especially note caveats for per-directory and
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen .htaccess context. <em><a href="/rewrite/flags.html#flag_l">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>next|N</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Re-run the rewriting process, starting again with the first
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen rule, using the result of the ruleset so far as a starting
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen point. <em><a href="/rewrite/flags.html#flag_n">details
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>nocase|NC</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Makes the pattern pattern comparison case-insensitive.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em><a href="/rewrite/flags.html#flag_nc">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>noescape|NE</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Prevent mod_rewrite from applying hexcode escaping of
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen special characters in the result of the rewrite. <em><a href="/rewrite/flags.html#flag_ne">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>nosubreq|NS</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Causes a rule to be skipped if the current request is an
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen internal sub-request. <em><a href="/rewrite/flags.html#flag_ns">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>proxy|P</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Force the substitution URL to be internally sent as a proxy
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen request. <em><a href="/rewrite/flags.html#flag_p">details
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>passthrough|PT</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Forces the resulting URI to be passed back to the URL
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen mapping engine for processing of other URI-to-filename
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen translators, such as <code>Alias</code> or
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <code>Redirect</code>. <em><a href="/rewrite/flags.html#flag_pt">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>qsappend|QSA</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Appends any query string created in the rewrite target to
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen any query string that was in the original request URL. <em><a href="/rewrite/flags.html#flag_qsa">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>qsdiscard|QSD</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Discard any query string attached to the incoming URI.
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <em><a href="/rewrite/flags.html#flag_qsd">details
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>redirect|R[=<em>code</em>]</td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Forces an external redirect, optionally with the specified
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen HTTP status code. <em><a href="/rewrite/flags.html#flag_r">details ...</a></em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>skip|S=<em>num</em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Tells the rewriting engine to skip the next <em>num</em>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen rules if the current rule matches. <em><a href="/rewrite/flags.html#flag_s">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>tyle|T=<em>MIME-type</em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen <td>Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen to be the specified type. <em><a href="/rewrite/flags.html#flag_t">details ...</a></em></td>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </tr>
ee9cda8f648f99a0b889cb0831ba5b1efe6b3eb5rbowen </table>
ff21ab9f1cc3037fe58a2029432834581594b6c4pctony
de68ca33425122cf4a880859013e08e84f8143a5covener<div class="note"><h3>Home directory expansion</h3>
de68ca33425122cf4a880859013e08e84f8143a5covener<p> When the substitution string begins with a string
de68ca33425122cf4a880859013e08e84f8143a5covenerresembling "/~user" (via explicit text or backreferences), mod_rewrite performs
81785f72c9d133aef57ad6b02f248345d90239aapoirierhome directory expansion independent of the presence or configuration
4e6d765a1b53690664877065e6b6c741c1b96937covenerof <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>.</p>
de68ca33425122cf4a880859013e08e84f8143a5covener
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>
de68ca33425122cf4a880859013e08e84f8143a5covener</div>
de68ca33425122cf4a880859013e08e84f8143a5covener
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<div class="note"><h3>Per-directory Rewrites</h3>
81785f72c9d133aef57ad6b02f248345d90239aapoirier
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>RewriteEngine On</code>" <strong>and</strong>
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
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
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe<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
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">&lt;Directory&gt;</a></code> section.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe
a4d04b8c74044c58bd4182028a1408d936c95951covener<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
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwroweshould never be necessary and is unsupported.</p>
beae3b927f4a40ba2f0b84d90cacfa1f0d528babwrowe
97a9a944b5887e91042b019776c41d5dd74557aferikabele</div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Here are all possible substitution combinations and their
06ba4a61654b3763ad65f52283832ebf058fdf1cslive meanings:</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Inside per-server configuration
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<code>httpd.conf</code>)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
97a9a944b5887e91042b019776c41d5dd74557aferikabele /somepath/pathinfo</code>'':</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 invalid, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 [R] invalid, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) otherpath$1 [P] invalid, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p><strong>Inside per-directory configuration for
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>/somepath</code><br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem (<code>/physical/path/to/somepath/.htacccess</code>, with
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>RewriteBase /somepath</code>)<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for request ``<code>GET
81785f72c9d133aef57ad6b02f248345d90239aapoirier /somepath/localpath/pathinfo</code>'':</strong><br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele<div class="note"><pre>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<strong>Given Rule</strong> <strong>Resulting Substitution</strong>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^localpath(.*) otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem^localpath(.*) /otherpath$1 [P] doesn't make sense, not supported
06ba4a61654b3763ad65f52283832ebf058fdf1cslive---------------------------------------------- ----------------------------------
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
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
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via external redirection
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (the [R] flag is redundant)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
06ba4a61654b3763ad65f52283832ebf058fdf1cslive via internal proxy
97a9a944b5887e91042b019776c41d5dd74557aferikabele</pre></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="bottomlang">
7dc5a2d4a0c77f5bf5a95de92d68e43de7d8117anilgun<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English">&nbsp;en&nbsp;</a> |
7dc5a2d4a0c77f5bf5a95de92d68e43de7d8117anilgun<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div><div id="footer">
50039065d571fe01fd458a3f031c995a1fd53c22rbowen<p class="apache">Copyright 2010 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>
0c0b2cdbccd4ddc8f07574c36444bf9a795a3e1cjim</body></html>