I\'d like to be able to do cross-context request forwarding in Tomcat with the Tuckey URLRewrite filter. For example, I\'d like to be able to route an incoming request with an
If your (real) webapp is deployed to /foo
and you want to on-the-fly rewrite URLs like /group-elements/baz
to forward (not redirect) to /foo/app/group/300245/elements
, then you're going to have to deploy your rewrite filter to one of two places: /group-elements
or /
.
The above configuration appears to be deploying to ROOT (which is /
) but then mapping the URL /baz
to /foo/app/group/300245/elements
. Instead, you probably want this:
<rule>
<from>/group-elements/baz</from>
<to context="foo">/foo/app/group/300245/elements</to>
</rule>
It looks like you were trying to hit http://example.com/baz
which I would have expected to work. The last bit of magic is going to be making the ROOT
context cross-context (note that your webapp does NOT need to be cross-context: only the urlrewrite one does). You can change the ROOT
webapp to be cross-context by addint crossContext="true"
to webapps/ROOT/META-INF/context.xml
.
Finally, you should really stop putting <Context>
elements in server.xml: leaving them in there basically means you need to restart Tomcat in order to change your webapp deployments.
After the comments I come do this possible conclusion:
I think you are mixing the concepts of a reverse proxy with cross-context. Cross-context is method to share data between two web-applications within the same application server. A reverse-proxy like 'Apache http' can rewrite a url to pass it to a certain server behind it, effectively hiding any unwanted parts or performing other operations like load-balancing.
The infrastructure would be: client --> reverse proxy --> application server