This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 68e5a7b23f Clarify the meaning of various RewriteValve server variables
68e5a7b23f is described below

commit 68e5a7b23f693876748d620335856ce22cdd8ebe
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Aug 28 11:15:21 2026 +0100

    Clarify the meaning of various RewriteValve server variables
---
 .../catalina/valves/rewrite/ResolverImpl.java      |  2 +-
 webapps/docs/changelog.xml                         |  5 ++
 webapps/docs/rewrite.xml                           | 75 ++++++++++------------
 3 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/java/org/apache/catalina/valves/rewrite/ResolverImpl.java 
b/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
index cda10c6849..8f5ddffb58 100644
--- a/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
+++ b/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
@@ -130,7 +130,7 @@ public class ResolverImpl extends Resolver {
         } else if (key.equals("REQUEST_PATH")) {
             return request.getRequestPathMB().toString();
         } else if (key.equals("CONTEXT_PATH")) {
-            return request.getContextPath();
+            return request.getServletContext().getContextPath();
         } else if (key.equals("SERVLET_PATH")) {
             return emptyStringIfNull(request.getServletPath());
         } else if (key.equals("PATH_INFO")) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 619dba3a6c..86eaf48f01 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -155,6 +155,11 @@
         <code>CrawlerSessionManagerValve</code> against crawlers being
         associated with an authenticated session. (markt)
       </add>
+      <fix>
+        Clarify the meaning of various RewriteValve server variables and
+        explicitly use the canonical context path for the
+        <code>CONTEXT_PATH</code> server variable. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">
diff --git a/webapps/docs/rewrite.xml b/webapps/docs/rewrite.xml
index 3ba98b8716..27014960d0 100644
--- a/webapps/docs/rewrite.xml
+++ b/webapps/docs/rewrite.xml
@@ -24,7 +24,7 @@
   &project;
 
   <properties>
-    <title>The rewrite Valve</title>
+    <title>The Rewrite Valve</title>
   </properties>
 
 <body>
@@ -41,17 +41,13 @@
   <p>The rewrite valve is configured as a valve using the 
<code>org.apache.catalina.valves.rewrite.RewriteValve</code>
   class name.</p>
 
-  <p>The rewrite valve can be configured as a valve added in a Host.
-     See <a href="config/host.html">virtual-server</a> documentation for
-     information on how to configure it. It will use a 
<code>rewrite.config</code> file
-     containing the rewrite directives, it must be placed in the Host 
configuration
-     folder.
-  </p>
+  <p>The rewrite valve can be configured as a valve added in a Host. See the 
<a href="config/host.html">Host</a>
+  documentation for information on how to configure it. The 
<code>rewrite.config</code> file containing the rewrite
+  directives must be placed in the Host configuration folder.</p>
 
-  <p>It can also be in the context.xml of a webapp.
-  The valve will then use a <code>rewrite.config</code> file containing the
-  rewrite directives, it must be placed in the WEB-INF folder of the web 
application
-  </p>
+  <p>The Valve can also be configured as a Valve added in a Context. The Valve 
must be added in the context.xml of a
+  webapp. The valve will then use the <code>rewrite.config</code> file 
containing the rewrite directives found in the
+  WEB-INF folder of the web application.</p>
 
 </section>
 
@@ -106,7 +102,7 @@
           (0 &lt;= N &lt;= 9), which provide access to the grouped
           parts (in parentheses) of the pattern, from the
           <code>RewriteRule</code> which is subject to the current
-          set of <code>RewriteCond</code> conditions..
+          set of <code>RewriteCond</code> conditions.
         </li>
         <li>
           <strong>RewriteCond backreferences</strong>: These are
@@ -197,45 +193,53 @@
           </li>
           </ul>
 
-                <p>These variables all
-                correspond to the similarly named HTTP
-                MIME-headers and Servlet API methods.
-                Most are documented elsewhere in the Manual or in
-                the CGI specification. Those that are special to
-                the rewrite valve include those below.</p>
+                <p>These variables correspond to the similarly named HTTP 
MIME-headers and Servlet API methods. Most are
+                documented in the Servlet API in the CGI specification. Those 
that are special to the rewrite valve
+                include those below.</p>
 
                 <dl>
 
                   <dt><code>REQUEST_PATH</code></dt>
 
-                  <dd>Corresponds to the full path that is used for 
mapping.</dd>
+                  <dd>Corresponds to the decoded, normalized path (excluding 
the context path) that is used for
+                  mapping.</dd>
 
                   <dt><code>CONTEXT_PATH</code></dt>
 
-                  <dd>Corresponds to the path of the mapped context.</dd>
+                  <dd>Corresponds to the canonical (decoded and normalized) 
path of the mapped context.</dd>
 
                   <dt><code>SERVLET_PATH</code></dt>
 
-                  <dd>Corresponds to the servlet path.</dd>
+                  <dd>Corresponds to 
<code>HttpServletRequest.getServletPath()</code>. The value is decoded and
+                  normalized.</dd>
+
+                  <dt><code>PATH_INFO</code></dt>
+
+                  <dd>Corresponds to 
<code>HttpServletRequest.getPathInfo()</code>. The value is decoded and
+                  normalized.</dd>
 
                   <dt><code>THE_REQUEST</code></dt>
 
-                  <dd>The full HTTP request line sent by the
-                  browser to the server (e.g., "<code>GET
-                  /index.html HTTP/1.1</code>"). This does not
-                  include any additional headers sent by the
-                  browser.</dd>
+                  <dd>The full HTTP request line sent by the browser to the 
server (e.g., "<code>GET /index.html
+                  HTTP/1.1</code>"). This does not include any additional 
headers sent by the browser.</dd>
 
                   <dt><code>REQUEST_URI</code></dt>
 
-                  <dd>The resource requested in the HTTP request
-                  line. (In the example above, this would be
-                  "/index.html".)</dd>
+                  <dd>The resource requested in the HTTP request line. (In the 
example above, this would be
+                  "/index.html".) Corresponds to 
<code>HttpServletRequest.getRequestURI()</code>. This is the original,
+                  non-decoded, non-normalized value and as such may not be 
suitable for many rewrite use cases. In most
+                  cases <code>%{CONTEXT_PATH}%{REQUEST_PATH}</code> will be 
more suitable than
+                  <code>%{REQUEST_URI}</code> </dd>
+
+                  <dt><code>SCRIPT_FILENAME</code></dt>
+
+                  <dd>The full local file system path to the file or script 
matching the request servlet path. The exact
+                  value returned is 
<code>ServletContext.getRealPath(HttpServletRequest.getServletPath()).</code></dd>
 
                   <dt><code>REQUEST_FILENAME</code></dt>
 
-                  <dd>The full local file system path to the file or
-                  script matching the request.</dd>
+                  <dd>The full local file system path to the file or script 
matching the request path info. The exact
+                  value returned is 
<code>ServletContext.getRealPath(HttpServletRequest.getPathInfo()).</code></dd>
 
                   <dt><code>HTTPS</code></dt>
 
@@ -250,15 +254,6 @@
       <p>Other things you should be aware of:</p>
 
       <ol>
-        <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME
-        contain the same value - the value of the
-        <code>filename</code> field of the internal
-        <code>request_rec</code> structure of the Apache server.
-        The first name is the commonly known CGI variable name
-        while the second is the appropriate counterpart of
-        REQUEST_URI (which contains the value of the
-        <code>uri</code> field of <code>request_rec</code>).</li>
-
         <li>
         <code>%{ENV:variable}</code>, where <em>variable</em> can be
         any Java system property, is also available.</li>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to