<li><img alt="" src="../images/down.gif" /> <a href="#rewriteoptions">RewriteOptions</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#rewriterule">RewriteRule</a></li>
</ul>
-<h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&list_id=144532&product=Apache%20httpd-2&query_format=specific&order=changeddate%20DESC%2Cpriority%2Cbug_severity&component=mod_rewrite">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&component=mod_rewrite">Report a bug</a></li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
+<h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&list_id=144532&product=Apache%20httpd-2&query_format=specific&order=changeddate%20DESC%2Cpriority%2Cbug_severity&component=mod_rewrite">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&component=mod_rewrite">Report a bug</a></li></ul><h3>See also</h3>
+<ul class="seealso">
+<li><a href="#comments_section">Comments</a></li></ul></div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="logging" id="logging">Logging</a></h2>
<code class="directive"><a href="#rewriterule">RewriteRule</a></code> directives that
substitute a relative path.</p>
<p> This directive is <em>required</em> when you use a relative path
- in a substitution in per-directory (htaccess) context unless either
+ in a substitution in per-directory (htaccess) context unless any
of the following conditions are true:</p>
<ul>
<li> The original request, and the substitution, are underneath the
suffixed by the relative
substitution is also valid as a URL path on the server
(this is rare).</li>
- <li> In Apache HTTP Server 2.4.11 and later, this directive may be
+ <li> In Apache HTTP Server 2.4.16 and later, this directive may be
omitted when the request is mapped via
<code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code>
or <code class="module"><a href="../mod/mod_userdir.html">mod_userdir</a></code>.</li>
<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>
</li>
- <li>
+ <li>
<p>If the <em>TestString</em> has the special value <code>expr</code>, the
<em>CondPattern</em> will be treated as an
<a href="../expr.html">ap_expr</a>.</p>
to block unwanted hotlinking.
</p>
- <pre class="prettyprint lang-config">RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"<br />
+ <pre class="prettyprint lang-config">RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
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>
extended URL and filesystem context information to change the
relative substitution back into a URL. Modules such as
<code class="module"><a href="../mod/mod_userdir.html">mod_userdir</a></code> and <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code>
- supply this extended context info. </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>
<p><a id="patterns" name="patterns"><em>Pattern</em></a> is
a perl compatible <a id="regexp" name="regexp">regular
- expression</a>. On the first RewriteRule, it is matched against
- the (%-decoded) <a href="directive-dict.html#Syntax">URL-path</a>
- of the request, or, in per-directory context (see below), the URL
- path relative to that per-directory context. Subsequent patterns
- are matched against the output of the last matching RewriteRule.</p>
+ expression</a>. What this pattern is compared against varies depending
+ 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,
- 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").</p>
- <p>In <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> and htaccess context,
- the <em>Pattern</em> will initially be matched against the
- <em>filesystem</em> path, after removing the prefix that led the server
- to the current <code class="directive">RewriteRule</code> (e.g. "app1/index.html"
- or "index.html" depending on where the directives are defined).</p>
+<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></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>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.
+ </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>
a user's directory, then you cannot use the rewrite engine. This
restriction is required for security reasons.</li>
-<li>When using the rewrite engine in <code>.htaccess</code> files the
-per-directory prefix (which always is the same for a specific
-directory) is automatically <em>removed</em> for the RewriteRule pattern matching
-and automatically <em>added</em> after any relative (not starting with a
-slash or protocol name) substitution encounters the end of a rule set.
-See the <code class="directive"><a href="#rewritebase">RewriteBase</a></code>
+<li>See the <code class="directive"><a href="#rewritebase">RewriteBase</a></code>
directive for more information regarding what prefix will be added back to
relative substitutions.</li>
<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>
}
})(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();