Background
I am using Spring Boot 1.4 in a simple Java application. As an experiment, I have decided to write my own servletContainer() bean to inject Tomcat's RewriteValve into the container. This valve is added as global context valve, and should apply to all requests.
I am using Tomcat 8.5.x.
Because the valve expects the configuration to be available inside a WEB-INF folder, I managed to override the startInternal() method of it to let it read the rewrite.config file under a classpath location that is containers/tomcat/rewrite.config.
The valve reads the configuration fine. The rewrite.config file simply states the following rule:
^/app2.+ /app
Meaning, rewrite the url to be /app when the request url begins with /app2.
It's important to note that the app itself is deployed under /app, and not under ROOT. This is handled via the server.context-path property.
What does not work
Since the app is deployed under /app, the valve is never really invoked when /app2 requests are submitted. For instance:
- http://localhost:8080/app2 never activates the valve
- http://localhost:8080/app/app2 activates the valve
If I remove the context-path and deploy /app under root, this is what I can observe:
- http://localhost:8080/app2 activates the valve
What works
Using an external tomcat container, if I manually configure the valve with the same rules, and deploy the app under /app, I can observe:
- http://localhost:8080/app2 activates the valve correctly. The url is rewritten to be http://localhost:8080/app
what might I be doing wrong?