I'm trying to use the Tomcat 9 rewrite Valve in order to redirect certain URLs to my Angular app, which is inside my spring app (very much like in this answer: https://stackoverflow.com/a/44847035/15773786).
As far as I see it I do have 2 approaches to do this:
- I place the line
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
in my server.xml under the Host tag and create arewrite.config
file under conf/Catalina/localhost with my redirect rules:
RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/mySpringApp/myAngularApp/(.*) /mySpringApp/myAngularApp/index.html
This configuration works for me like a charme without any problems.
But ofc this configuration is 'invasive', so I'd like to configure this inside of my app.
- For this Tomcat gives me the option to configure it in my
META-INF/context.xml
:
<Context>
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
</Context>
I should then be able to put the rewrite-config
inside my WEB-INF folder and if I start my app...
...it does not work! The question is why. Anyone got an idea?
What I also tried for the second configuration option:
- changing the first line of
rewrite-config
toRewriteCond %{SERVLET_PATH} !-f
as suggested in the post mentioned above - completely deleting the
RewriteCond
I tried to add a line "break_it" into my rewrite.config in the WEB-INF folder and this broke the startup of tomcat saying "invalid line". So the rewrite.config is read, but has no effect.