mod_rewrite.html.en revision d229f940abfb2490dee17979e9a5ff31b7012eb5
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd This file is generated from xml source: DO NOT EDIT
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<script src="/style/scripts/prettify.js" type="text/javascript">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<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.5</a> > <a href="./">Modules</a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<p><span>Available Languages: </span><a href="/en/mod/mod_rewrite.html" title="English"> en </a> |
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<a href="/fr/mod/mod_rewrite.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>rewrite_module</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_rewrite.c</td></tr></table>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>The <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> module uses a rule-based rewriting
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd engine, based on a PCRE regular-expression parser, to rewrite requested URLs on
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd the fly. By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> maps a URL to a filesystem
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd path. However, it can also be used to redirect one URL to another URL, or
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd to invoke an internal proxy fetch.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> provides a flexible and powerful way to
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd manipulate URLs using an unlimited number of rules. Each rule can have an
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd unlimited number of attached rule conditions, to allow you to rewrite URL
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd based on server variables, environment variables, HTTP headers, or time
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd stamps.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> operates on the full URL path, including the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd path-info section. A rewrite rule can be invoked in
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code>httpd.conf</code> or in <code>.htaccess</code>. The path generated
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd by a rewrite rule can include a query string, or can lead to internal
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd sub-processing, external request redirection, or internal proxy
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd throughput.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>Further details, discussion, and examples, are provided in the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <a href="/rewrite/">detailed mod_rewrite documentation</a>.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div id="quickview"><h3 class="directives">Directives</h3>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritebase">RewriteBase</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritecond">RewriteCond</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteengine">RewriteEngine</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewritemap">RewriteMap</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<li><img alt="" src="/images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<li><img alt="" src="/images/down.gif" /> <a href="#logging">Logging</a></li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> offers detailed logging of its actions
a78048ccbdb6256da15e6b0e7e95355e480c2301nd at the <code>trace1</code> to <code>trace8</code> log levels. The
a78048ccbdb6256da15e6b0e7e95355e480c2301nd log level can be set specifically for <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd using the <code class="directive"><a href="/mod/core.html#loglevel">LogLevel</a></code> directive: Up to
a78048ccbdb6256da15e6b0e7e95355e480c2301nd level <code>debug</code>, no actions are logged, while <code>trace8</code>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd means that practically all actions are logged.</p>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd Using a high trace log level for <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd will slow down your Apache HTTP Server dramatically! Use a log
a78048ccbdb6256da15e6b0e7e95355e480c2301nd level higher than <code>trace2</code> only for debugging!
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd LogLevel alert rewrite:trace3
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>Those familiar with earlier versions of
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> will no doubt be looking for the
05ede5110427cb9dc071cc671d5aaba5d3b88c79nd directives. This functionality has been completely replaced by the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd new per-module logging configuration mentioned above.
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>To get just the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>-specific log
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd messages, pipe the log file through grep:</p>
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd tail -f error_log|fgrep '[rewrite:'
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd<div class="directive-section"><h2><a name="RewriteBase" id="RewriteBase">RewriteBase</a> <a name="rewritebase" id="rewritebase">Directive</a></h2>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets the base URL for per-directory rewrites</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RewriteBase <em>URL-path</em></code></td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None</code></td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory, .htaccess</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>The <code class="directive">RewriteBase</code> directive specifies the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd URL prefix to be used for per-directory (htaccess)
d2b809e5d72658bff23819d8b77f20e4939af541nd <code class="directive">RewriteRule</code> directives that substitute a relative
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p> This directive is <em>required</em> when you use a relative path
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd in a substitution in per-directory (htaccess) context unless either
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd of the following conditions are true:</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <li> The original request, and the substitution, are underneath the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd (as opposed to reachable by other means, such as
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code>).</li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <li> The <em>filesystem</em> path to the directory containing the
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <code class="directive">RewriteRule</code>, suffixed by the relative
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd substitution is also valid as a URL path on the server
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd (this is rare).</li>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<p> In the example below, <code class="directive">RewriteBase</code> is necessary
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd since the resource was not relative to the document root. This
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd misconfiguration would normally cause the server to look for an "opt"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd directory under the document root.</p>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd RewriteEngine On
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd RewriteBase /myapp/
a78048ccbdb6256da15e6b0e7e95355e480c2301nd RewriteRule ^index\.html$ welcome.html
a78048ccbdb6256da15e6b0e7e95355e480c2301nd</Directory>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<div class="directive-section"><h2><a name="RewriteCond" id="RewriteCond">RewriteCond</a> <a name="rewritecond" id="rewritecond">Directive</a></h2>
03c25fb6f628ac81f2ecb637d1e7502dcee783f3nd<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <em>TestString</em> <em>CondPattern</em></code></td></tr>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_rewrite</td></tr>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd <p>The <code class="directive">RewriteCond</code> directive defines a
35714556a25fceb7c9bf9c4e01791b2e2a4c27c3nd rule condition. One or more <code class="directive">RewriteCond</code>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd can precede a <code class="directive"><a href="#rewriterule">RewriteRule</a></code>
0853e1e2522c1ac17f697221758bcbd4781a7ff9nd directive. The following rule is then only used if both
the current state of the URI matches its pattern, <strong>and</strong> if these conditions are met.</p>
<code class="directive"><a href="/mod/core.html#usecanonicalphysicalport">UseCanonicalPhysicalPort</a></code>
such as "/index.html". This notably excludes the
<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
<p>By default, <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> will ignore URLs that map to a
the <code class="module"><a href="/mod/mod_dir.html">mod_dir</a></code> module will issue the client with a redirect to
<p>When the <code class="directive"><a href="/mod/mod_dir.html#directoryslash">DirectorySlash</a></code> directive
<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>In <code class="directive"><a href="/mod/core.html#directory">Directory</a></code> and htaccess context,
<li>The rewrite engine may be used in <a href="/howto/htaccess.html">.htaccess</a> files and in <code class="directive"><a href="/mod/core.html#directory"><Directory></a></code> sections, with some additional
<li>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
<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
in the config file. The URL-path or file-system path (see <a href="#what_is_matched">"What is matched?"</a>, above) is <strong>completely
<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>
the environment variable <em>VAR</em> to be unset.<em><a href="/rewrite/flags.html#flag_e">details ...</a></em></td>
<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>
.htaccess context (see also the END flag). <em><a href="/rewrite/flags.html#flag_l">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 created in the rewrite target.<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><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 2012 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="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--