From: Rich Bowen Date: Wed, 20 May 2026 20:52:39 +0000 (+0000) Subject: rewrite: warn that // silently switch to per-directory context X-Git-Tag: 2.4.68-rc1-candidate~106 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9dd7c117fc31b35b3282660bd3088153839bed0;p=thirdparty%2Fapache%2Fhttpd.git rewrite: warn that // silently switch to per-directory context git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1934452 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/htaccess.xml b/docs/manual/rewrite/htaccess.xml index 6d5d0b61c2..a11ff66739 100644 --- a/docs/manual/rewrite/htaccess.xml +++ b/docs/manual/rewrite/htaccess.xml @@ -340,4 +340,39 @@ performance. +
Which contexts support rewrite rules? + +

Rewrite rules are supported in +per-directory context +(.htaccess files, +Directory, and +If blocks).

+ +

Although rewrite rules are syntactically permitted in +Location +and Files +sections (including their regex counterparts), this is +unsupported and should never be necessary. Relative +substitutions, in particular, are likely to break in +these contexts.

+ +These containers silently change rewrite +behavior +

Placing a RewriteRule +inside a Directory, +If, or +Location block +— even inside a +VirtualHost in the +main server config — silently switches to +per-directory context behavior. +This means the leading slash is stripped from the URL before pattern +matching, substitutions trigger an internal redirect (with loop risk), +and the [L] flag no longer +truly stops processing — use +[END] instead.

+
+ +
+ diff --git a/docs/manual/rewrite/intro.xml b/docs/manual/rewrite/intro.xml index 95b98c9623..eceb468fe3 100644 --- a/docs/manual/rewrite/intro.xml +++ b/docs/manual/rewrite/intro.xml @@ -391,7 +391,12 @@ recommended. It is possible, however, to do rewriting inside Directory sections or .htaccess files at the expense of some additional complexity. This technique -is called per-directory rewrites.

+is called per-directory rewrites. +Note that +If and +Location blocks +also trigger per-directory behavior — see +Which contexts support rewrite rules?.

The main difference from per-server rewrites is that the path prefix of the directory containing the .htaccess file is