]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
rewrite: warn that <If>/<Location>/<Directory> silently switch to per-directory context
authorRich Bowen <rbowen@apache.org>
Wed, 20 May 2026 20:52:39 +0000 (20:52 +0000)
committerRich Bowen <rbowen@apache.org>
Wed, 20 May 2026 20:52:39 +0000 (20:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1934452 13f79535-47bb-0310-9956-ffa450edef68

docs/manual/rewrite/htaccess.xml
docs/manual/rewrite/intro.xml

index 6d5d0b61c2f66d397b1dfe8258eb2a397328c4ff..a11ff66739543efd796774d01829f24bdf93ba5c 100644 (file)
@@ -340,4 +340,39 @@ performance.</note>
 
 </section>
 
+<section id="context-restrictions"><title>Which contexts support rewrite rules?</title>
+
+<p>Rewrite rules are supported in
+<glossary ref="perdirectory">per-directory context</glossary>
+(<a href="../howto/htaccess.html">.htaccess</a> files,
+<directive module="core" type="section">Directory</directive>, and
+<directive module="core" type="section">If</directive> blocks).</p>
+
+<p>Although rewrite rules are syntactically permitted in
+<directive module="core" type="section">Location</directive>
+and <directive module="core" type="section">Files</directive>
+sections (including their regex counterparts), this is
+unsupported and should never be necessary. Relative
+substitutions, in particular, are likely to break in
+these contexts.</p>
+
+<note type="warning"><title>These containers silently change rewrite
+behavior</title>
+<p>Placing a <directive module="mod_rewrite">RewriteRule</directive>
+inside a <directive module="core" type="section">Directory</directive>,
+<directive module="core" type="section">If</directive>, or
+<directive module="core" type="section">Location</directive> block
+&mdash; even inside a
+<directive module="core" type="section">VirtualHost</directive> in the
+main server config &mdash; silently switches to
+<glossary ref="perdirectory">per-directory context</glossary> behavior.
+This means the leading slash is stripped from the URL before pattern
+matching, substitutions trigger an internal redirect (with loop risk),
+and the <a href="../rewrite/flags.html#flag_l">[L]</a> flag no longer
+truly stops processing &mdash; use
+<a href="../rewrite/flags.html#flag_end">[END]</a> instead.</p>
+</note>
+
+</section>
+
 </manualpage>
index 95b98c96231dae51d4b7234d2f6809c5d60c71e4..eceb468fe30987fd1a010023cab27bfe04090ec0 100644 (file)
@@ -391,7 +391,12 @@ recommended. It is possible, however, to do rewriting
 inside <directive type="section" module="core">Directory</directive>
 sections or <a href="../howto/htaccess.html"><code>.htaccess</code>
 files</a> at the expense of some additional complexity. This technique
-is called <glossary ref="perdirectory">per-directory</glossary> rewrites.</p>
+is called <glossary ref="perdirectory">per-directory</glossary> rewrites.
+Note that
+<directive module="core" type="section">If</directive> and
+<directive module="core" type="section">Location</directive> blocks
+also trigger per-directory behavior &mdash; see
+<a href="htaccess.html#context-restrictions">Which contexts support rewrite rules?</a>.</p>
 
 <p>The main difference from per-server rewrites is that the path
 prefix of the directory containing the <code>.htaccess</code> file is