Forwarding requests between contexts in Tomcat

后端 未结 2 602
臣服心动
臣服心动 2021-02-10 05:23

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

2条回答
  •  我在风中等你
    2021-02-10 05:26

    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:

    
        /group-elements/baz
        /foo/app/group/300245/elements
    
    

    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 elements in server.xml: leaving them in there basically means you need to restart Tomcat in order to change your webapp deployments.

提交回复
热议问题