<div id="page-content">
<div id="preamble"><h1>Apache Module mod_rewrite</h1>
<div class="toplang">
-<p><span>Available Languages: </span><a href="../edited/mod/mod_rewrite.html" hreflang="edited" rel="alternate" title=""> edited </a> |
-<a href="../en/mod/mod_rewrite.html" title="English"> en </a> |
+<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>
</div>
<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides a rule-based rewriting engine to rewrite requested
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Defines a condition under which rewriting will take place
</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code> RewriteCond
- <em>TestString</em> <em>CondPattern</em></code></td></tr>
+ <em>TestString</em> <em>CondPattern</em> [<em>flags</em>]</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
RewriteRule "^/images" "-" [F]</pre>
</li>
+ </ol>
- <li>You can also set special flags for
- <em>CondPattern</em> by appending
+ <p>You can also set special flags for <em>CondPattern</em> by appending
<strong><code>[</code><em>flags</em><code>]</code></strong>
as the third argument to the <code>RewriteCond</code>
directive, where <em>flags</em> is a comma-separated list of any of the
- following flags:
-
+ following flags:</p>
+
<ul>
<li>'<strong><code>nocase|NC</code></strong>'
(<strong>n</strong>o <strong>c</strong>ase)<br />
is well understood.
</li>
</ul>
- </li>
- </ol>
<p><strong>Example:</strong></p>
supply this extended context info. Available in 2.4.16 and later.</p>
</dd>
+
+ <dt><code>LegacyPrefixDocRoot</code></dt>
+ <dd>
+
+ <p>Prior to 2.4.26, if a substitution was an absolute URL that matched
+ the current virtual host, the URL might first be reduced to a URL-path
+ and then later reduced to a local path. Since the URL can be reduced
+ to a local path, the path should be prefixed with the document root.
+ This prevents a file such as /tmp/myfile from being accessed when a
+ request is made to http://host/file/myfile with the following
+ <code class="directive"><a href="#rewriterule">RewriteRule</a></code>.</p>
+ <pre class="prettyprint lang-config">RewriteRule /file/(.*) http://localhost/tmp/$1</pre>
+
+ <p>This option allows the old behavior to be used where the document
+ root is not prefixed to a local path that was reduced from a
+ URL. Available in 2.4.26 and later.</p>
+ </dd>
+
</dl>
</div>
on where the <code class="directive">RewriteRule</code> directive is defined. </p>
<div class="note"><h3><a id="what_is_matched" name="what_is_matched">What is matched?</a></h3>
- <p>In <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> context,
+
+<ul>
+ <li><p>In <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> context,
The <em>Pattern</em> will initially be matched against the part of the
URL after the hostname and port, and before the query string (e.g. "/app1/index.html").
- This is the (%-decoded) <a href="directive-dict.html#Syntax">URL-path</a>.</p>
+ This is the (%-decoded) <a href="directive-dict.html#Syntax">URL-path</a>.</p></li>
+
+ <li><p>In per-directory context (<code class="directive"><a href="../mod/core.html#directory">Directory</a></code> and .htaccess),
+ the <em>Pattern</em> is matched against only a partial path, for example a request
+ of "/app1/index.html" may result in comparison against "app1/index.html"
+ or "index.html" depending on where the <code class="directive">RewriteRule</code> is
+ defined.</p>
- <p>In <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> and htaccess context,
- the <em>Pattern</em> is matched against the trailing portion of the currently
- mapped filesystem path with the rules own directory path removed from the beginning
- (up to and including a trailing slash). Directives such as <code class="directive">DocumentRoot</code> and <code class="directive">Alias</code>, or even the
+ <p>The directory path where the rule is defined is stripped from the currently mapped
+ filesystem path before comparison (up to and including a trailing slash).
+ The net result of this per-directory prefix stripping is that rules in
+ this context only match against the portion of the currently mapped filesystem path
+ "below" where the rule is defined.</p>
+
+ <p>Directives such as <code class="directive">DocumentRoot</code> and <code class="directive">Alias</code>, or even the
result of previous <code class="directive">RewriteRule</code> substitutions, determine
- the currently mapped filesystem path. The net result of this per-directory
- prefix stripping is that rules in this context only match against the portion
- of the currently mapped path "below" where they are defined.</p>
+ the currently mapped filesystem path.
+ </p>
+ </li>
- <p>If you wish to match against the hostname, port, or query string, use a
+ <li><p>If you wish to match against the hostname, port, or query string, use a
<code class="directive"><a href="#rewritecond">RewriteCond</a></code> with the
<code>%{HTTP_HOST}</code>, <code>%{SERVER_PORT}</code>, or
- <code>%{QUERY_STRING}</code> variables respectively.</p>
-
- <p>In any case, remember that regular expressions are substring
- matches. That is, you don't need the regex to describe the entire
- string, just the part that you wish to match. Thus, using a regex
- of <code>.</code> is often sufficient rather than <code>.*</code>,
- and the regex <code>abc</code> is <strong>not</strong> the same as
- <code>^abc$</code>.</p>
-
+ <code>%{QUERY_STRING}</code> variables respectively.</p></li>
+</ul>
</div>
<div class="note"><h3>Per-directory Rewrites</h3>
<tr class="odd">
<td>qslast|QSL</td>
<td>Interpret the last (right-most) question mark as the query string
- delimeter, instead of the first (left-most) as normally used.
+ delimiter, instead of the first (left-most) as normally used.
Available in 2.4.19 and later.
<em><a href="../rewrite/flags.html#flag_qsl">details
...</a></em></td>
</div>
</div>
<div class="bottomlang">
-<p><span>Available Languages: </span><a href="../edited/mod/mod_rewrite.html" hreflang="edited" rel="alternate" title=""> edited </a> |
-<a href="../en/mod/mod_rewrite.html" title="English"> en </a> |
+<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>
</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
<script type="text/javascript"><!--//--><![CDATA[//><!--
}
})(window, document);
//--><!]]></script></div><div id="footer">
-<p class="apache">Copyright 2016 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="apache">Copyright 2017 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/quickreference.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[//><!--
if (typeof(prettyPrint) !== 'undefined') {
prettyPrint();