mod_rewrite.html.en revision 1f0a28764a0520e43ce3a9130e56236fd67cd568
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><!--
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive This file is generated from xml source: DO NOT EDIT
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b686b6a420bde7f78c416b90be11db94cb789979nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
b686b6a420bde7f78c416b90be11db94cb789979nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
b686b6a420bde7f78c416b90be11db94cb789979nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
b686b6a420bde7f78c416b90be11db94cb789979nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
b686b6a420bde7f78c416b90be11db94cb789979nd<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>
b686b6a420bde7f78c416b90be11db94cb789979nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Modules</a></div>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a> |
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p>
b686b6a420bde7f78c416b90be11db94cb789979nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr></table>
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd <p>The <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> module uses a rule-based rewriting
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd engine, based on a regular-expression parser, to rewrite requested URLs on
5b10fd3977e6dfff19afe770e612e276962f7950nd the fly. By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> maps a URL to a filesystem
5b10fd3977e6dfff19afe770e612e276962f7950nd path. However, it can also be used to redirect one URL to another URL, or
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd to invoke an internal proxy fetch.</p>
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> provides a flexible and powerful way to
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd manipulate URLs using an unlimited number of rules. Each rule can have an
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd unlimited number of attached rule conditions, to allow you to rewrite URL
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd based on server variables, environment variables, HTTP headers, or time
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd stamps.</p>
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> operates on the full URL path, including the
5b10fd3977e6dfff19afe770e612e276962f7950nd path-info section. A rewrite rule can be invoked in
5b10fd3977e6dfff19afe770e612e276962f7950nd <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd by a rewrite rule can include a query string, or can lead to internal
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd sub-processing, external request redirection, or internal proxy
2aff288113d772cedca6add888eb643afffe9fb1nd throughput.</p>
2aff288113d772cedca6add888eb643afffe9fb1nd <p>Further details, discussion, and examples, are provided in the
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
7fa75a06a4fee19e995c069ee00310455d1452e1pquerna<div id="quickview"><h3 class="directives">Directives</h3>
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
2aff288113d772cedca6add888eb643afffe9fb1nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
2aff288113d772cedca6add888eb643afffe9fb1nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
2aff288113d772cedca6add888eb643afffe9fb1nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> offers detailed logging of its actions
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd at the <code>trace1</code> to <code>trace8</code> log levels. The
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd log level can be set specifically for <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
2aff288113d772cedca6add888eb643afffe9fb1nd using the <code class="directive"><a href="/mod/core.html#loglevel">LogLevel</a></code> directive: Up to
2aff288113d772cedca6add888eb643afffe9fb1nd level <code>debug</code>, no actions are logged, while <code>trace8</code>
2aff288113d772cedca6add888eb643afffe9fb1nd means that practically all actions are logged.</p>
2aff288113d772cedca6add888eb643afffe9fb1nd Using a high trace log level for <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
2aff288113d772cedca6add888eb643afffe9fb1nd will slow down your Apache HTTP Server dramatically! Use a log
2aff288113d772cedca6add888eb643afffe9fb1nd level higher than <code>trace2</code> only for debugging!
aa0b2780958e9b1467c9d0153a05738e399811a5nd LogLevel rewrite:trace3
2aff288113d772cedca6add888eb643afffe9fb1nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
aa0b2780958e9b1467c9d0153a05738e399811a5nd<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
64c02f1310b7747423957823ee09fb3608430f89nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
aa0b2780958e9b1467c9d0153a05738e399811a5nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd <p>The <code class="directive">RewriteBase</code> directive explicitly
2aff288113d772cedca6add888eb643afffe9fb1nd sets the base URL-path (not filesystem directory path!) for per-directory rewrites.
2aff288113d772cedca6add888eb643afffe9fb1nd When you use a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
2aff288113d772cedca6add888eb643afffe9fb1nd in a <code>.htaccess</code> file, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> strips off
2aff288113d772cedca6add888eb643afffe9fb1nd the local directory prefix before processing, then rewrites the rest of
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd the URL. When the rewrite is completed, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
2aff288113d772cedca6add888eb643afffe9fb1nd automatically adds the local directory prefix back on to the path.</p>
05ede5110427cb9dc071cc671d5aaba5d3b88c79nd <p>This directive is <em>required</em> for per-directory rewrites whose context
e8b603fa9ccf7b17b11b42df6d8916fd97c2331dnd is a directory made available via the <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>
bf94bedcb62d7f0b926f4286069def5ee6b07b60nd directive.</p>
2aff288113d772cedca6add888eb643afffe9fb1nd <p>If your URL path does not exist verbatim on the filesystem,
2aff288113d772cedca6add888eb643afffe9fb1nd or isn't directly under your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>,
bbcbf978a3074512c627c797fedcb30eeab7b39dslive you must use <code class="directive">RewriteBase</code> in every
ee5db395bc3723609919edfa96af387eea37c491jim <code>.htaccess</code> file where you want to use <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives.</p>
2aff288113d772cedca6add888eb643afffe9fb1nd <p>The example below demonstrates how to map
e55e60efce8a3e2139132c1d6ad9f6f0d2976614nd /home/www/example/newsite.html, in a <code>.htaccess</code> file. This
2aff288113d772cedca6add888eb643afffe9fb1nd assumes that the content available at
7f3fdc63be07f2ad39e01a44e68e9324998a5c03slive http://example.com/ is on disk at /home/www/example/</p>
7f3fdc63be07f2ad39e01a44e68e9324998a5c03sliveRewriteEngine On
75585bd48fe0f30483dba4762e61edf39ea3e0f6nd# The URL-path used to get to this context, not the filesystem path
75585bd48fe0f30483dba4762e61edf39ea3e0f6ndRewriteBase /myapp/
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42ndRewriteRule ^index\.html$ newsite.html
7d15331eeb5429d7148d13d6fd914a641bf1c000pquerna<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
2aff288113d772cedca6add888eb643afffe9fb1nd<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
08842292d2f1550b40ae73e0dafc7641c5955c82nd <em>TestString</em> <em>CondPattern</em></code></td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
d2b809e5d72658bff23819d8b77f20e4939af541nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
2aff288113d772cedca6add888eb643afffe9fb1nd <p>The <code class="directive">RewriteCond</code> directive defines a
2aff288113d772cedca6add888eb643afffe9fb1nd rule condition. One or more <code class="directive">RewriteCond</code>
2aff288113d772cedca6add888eb643afffe9fb1nd can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
2aff288113d772cedca6add888eb643afffe9fb1nd directive. The following rule is then only used if both
2aff288113d772cedca6add888eb643afffe9fb1nd the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd following expanded constructs in addition to plain text:</p>
73ba54c33b4fcad0e13005e10ea8648c9fe4265bnd backreferences of the form <strong><code>$N</code></strong>
73ba54c33b4fcad0e13005e10ea8648c9fe4265bnd (0 <= N <= 9). $1 to $9 provide access to the grouped
73ba54c33b4fcad0e13005e10ea8648c9fe4265bnd parts (in parentheses) of the pattern, from the
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd access to the whole string matched by that pattern.
2aff288113d772cedca6add888eb643afffe9fb1nd backreferences of the form <strong><code>%N</code></strong>
2aff288113d772cedca6add888eb643afffe9fb1nd (0 <= N <= 9). %1 to %9 provide access to the grouped
2aff288113d772cedca6add888eb643afffe9fb1nd parts (again, in parentheses) of the pattern, from the last matched
2aff288113d772cedca6add888eb643afffe9fb1nd of conditions. %0 provides access to the whole string matched by
2aff288113d772cedca6add888eb643afffe9fb1nd that pattern.
2aff288113d772cedca6add888eb643afffe9fb1nd expansions of the form <strong><code>${mapname:key|default}</code></strong>.
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd RewriteMap</a> for more details.
2aff288113d772cedca6add888eb643afffe9fb1nd <strong>Server-Variables</strong>: These are variables of
2aff288113d772cedca6add888eb643afffe9fb1nd from the following list:
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <th>HTTP headers:</th> <th>connection & request:</th> <th />
b686b6a420bde7f78c416b90be11db94cb789979nd HTTP_USER_AGENT<br />
80d3dc69b0e6ad772135f6a78af3d16bd6cccc42nd HTTP_REFERER<br />
<code class="module"><a href="/mod/mod_ssl.html">mod_ssl</a></code> is loaded, but will always expand to
RewriteRule ...some special stuff for any of these hosts...
RewriteRule ^/$ /homepage.max.html [L]
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
<div class="directive-section"><h2><a name="RewriteEngine" id="RewriteEngine">RewriteEngine</a> <a name="rewriteengine" id="rewriteengine">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enables or disables runtime rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteEngine on|off</code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RewriteEngine off</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
commenting out all the <code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives!</p>
<div class="directive-section"><h2><a name="RewriteMap" id="RewriteMap">RewriteMap</a> <a name="rewritemap" id="rewritemap">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a mapping function for key-lookup</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The choice of different dbm types is available in
<dd>Randomly selects an entry from a plain text file (<a href="/rewrite/rewritemap.html#rnd">Details ...</a>)</dd>
<p>Further details, and numerous examples, may be found in the <a href="/rewrite/rewritemap.html">RewriteMap HowTo</a></p>
<div class="directive-section"><h2><a name="RewriteOptions" id="RewriteOptions">RewriteOptions</a> <a name="rewriteoptions" id="rewriteoptions">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets some special options for the rewrite engine</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteOptions <var>Options</var></code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><code>MaxRedirects</code> is no longer available in version 2.1 and
<div class="directive-section"><h2><a name="RewriteRule" id="RewriteRule">RewriteRule</a> <a name="rewriterule" id="rewriterule">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines rules for the rewriting engine</td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<p>For some hints on <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
<dd>A <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>-relative path to the
resource to be served. Note that <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
URL-mapping directives (such as <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>) to be applied to the
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> checks to see whether the
<p>Additionally you can set special <a name="rewriteflags" id="rewriteflags">actions</a> to be performed by
details, and examples, for each flag, are available in the <a href="/rewrite/flags.html">Rewrite Flags document</a>.</p>
the rule(s) chained to it will be skipped. <em><a href="/rewrite/flags.html#flag_c">details ...</a></em></td>
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>
<td>Returns a 410 GONE response to the client browser. <em><a href="/rewrite/flags.html#flag_g">details ...</a></em></td>
<em>Content-handler</em> for processing. <em><a href="/rewrite/flags.html#flag_h">details ...</a></em></td>
special characters in the result of the rewrite. <em><a href="/rewrite/flags.html#flag_ne">details ...</a></em></td>
any query string that was in the original request URL. <em><a href="/rewrite/flags.html#flag_qsa">details ...</a></em></td>
rules if the current rule matches. <em><a href="/rewrite/flags.html#flag_s">details ...</a></em></td>
<td>Force the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME-type</a> of the target file
<p>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files. To enable the
<p>The rewrite engine may also be used in <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> sections with the same
virtual host context, rather than in a <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> section.</p>
<p>Although rewrite rules are syntactically permitted in <code class="directive"><a href="/mod/core.html#location"><Location></a></code> and <code class="directive"><a href="/mod/core.html#files"><Files></a></code> sections, this
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a> |
<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p>
<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>
<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>