https://bz.apache.org/bugzilla/show_bug.cgi?id=64593

            Bug ID: 64593
           Summary: Rewrites incorrectly 404 when there is no source
                    context
           Product: Tomcat 8
           Version: 8.5.57
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: n...@worldofnic.org
  Target Milestone: ----

If you enable rewrites, and put a rewrite.config in, where the source
location does not match a valid context, the server issues a 404. The
server then logs a 404 in the access log for the target location.

I would argue that the server should perform the rewrite and return the
target's content. However, if that is not what is meant to happen, then
the logged 404 should be for the source URL, not the target.

In "Bonus Step 8." below, you can see that the server _thinks_ the rewrite rule
is present and that it has rewritten the request.

Step 1. Enable Rewrite valve via

<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

Step 2. Add a rewrite.config to conf/Catalina/localhost containing:

RewriteRule ^/source/(.*)$ /target/$1 [L]

Step 3. Delete all webapps

rm -rf webapps/*

Step 4. Create webapps/target/index.html

Step 5. Start server

Step 6. Test Rewrite

curl -I http://localhost:8080/source/index.html
HTTP/1.1 404

Step 7. Observe rewritten path in logs:

0:0:0:0:0:0:0:1 - - [10/Jul/2020:18:44:06 +0100] "HEAD /target/index.html
HTTP/1.1" 404 -

Bonus Step 8. Enable FINE logging, and we get the following lines:

10-Jul-2020 19:27:36.803 FINE [Catalina-startStop-1]
org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with pattern
^/source/(.*)$ and substitution /target/$1

org.apache.catalina.valves.rewrite.RewriteValve.invoke Rewrote
/source/index.html as /target/index.html with rule pattern ^/source/(.*)$

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to