Am 20.02.2015 08:49, schrieb Rainer Jung:
Am 19.02.2015 um 22:13 schrieb Felix Schumacher:
Am 19.02.2015 um 21:41 schrieb André Warnier:
Jérémie Barthés wrote:
...


Make a file rewrite.config in conf/Catalina/localhost/ that contains :
RewriteRule    ^/mypath/(.*)$    /examples/jsp/$1

copy the line
        <Valve
className="org.apache.catalina.valves.rewrite.RewriteValve" />
in the conf/server.xml file, line 131


Since this is a Valve, it will run before Tomcat attempts to match the
URL to an actual directory or webapp.


try the followings URLs :


1) http://localhost:8080/mypath/async

This matches the rewrite rule, so it will be rewritten to URL

  /examples/jsp/async

Then Tomcat will attempt to match this to a directory or webapp, and
find that (catalina_base)/webapps/examples/jsp/async is a directory.
It will thus respond to the browser with a 302 re-direct to

   http://localhost:8080/examples/jsp/async/

which is actually the "correct" URL.
And this is what will be shown in the browser URL bar.  This, in my
view, is expected behaviour.  The server does that, so that when an
actual response is generated (for the correct URL
http://localhost:8080/examples/jsp/async/), the browser can cache this
response under the correct URL.

Then the browser re-issues a request for

   http://localhost:8080/examples/jsp/async/

and that is when Tomcat will actually generate a "real" response,
because this time it is a correct URL. So the response appears to the
browser, as coming from

   http://localhost:8080/examples/jsp/async/

which is correct.

2) http://localhost:8080/mypath/async/

This also matches the rewrite rule, so it gets rewritten to

http://localhost:8080/examples/jsp/async/

which is a correct URL.
Thus Tomcat will immediately generate a real response (without an
intermediate 302 redirect), which will be appear in the browser URL
bar as a response to

http://localhost:8080/mypath/async/

This is also expected behaviour.

I believe that if you do not want to see the first redirect URL

   http://localhost:8080/examples/jsp/async/

in the browser, you have to modify your rewrite rules, perhaps by
using a RewriteCond with the -d flag, to check first if the URL points
to an existing directory, and if yes add the terminating "/" yourself
(with a RewriteRule) before other rewrite tests/rules take place.
This rewrite.config

...

will do the trick. I think -d will not work, since /mypath/async is not
existant, it only "feels" like a directory.

Not clear: the implementation for "-d" is (case 0 below, from file
ResolverImpl.java):

148     @Override
149     public boolean resolveResource(int type, String name) {
150 WebResourceRoot resources = request.getContext().getResources();
151         WebResource resource = resources.getResource(name);
152         if (!resource.exists()) {
153             return false;
154         } else {
155             switch (type) {
156             case 0:
157                 return (resource.isDirectory());
158             case 1:
159                 return (resource.isFile());
160             case 2:
161                 return (resource.isFile() &&
resource.getContentLength() > 0);
162             default:
163                 return false;
164             }
165         }
166     }

Since it checks resources and the OP was actually talking about a path
that is a folder in his webapp, "-d" could work.

Right, but given the examples and instructions from the op, it seems to me, that async (source) is not a directory.

I think the op wants to mimic [P] behaviour, which is not implemented and wants to point out that the valve behaves differently when operating on a directory like url and one that is not. In the former it will do an internal forward in the latter an external redirect.

As proxy mode is not supported and documented, I tend to say, that it is a mildly annoying
inconsitency, but not a bug per se.

Regards
 Felix


Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to