0

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:

  1. I place the line <Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/> in my server.xml under the Host tag and create a rewrite.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.

  1. 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 to RewriteCond %{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.

1 Answers1

0

For anyone haveing similar issues, I found the solution. This answer to a related post helped me: https://stackoverflow.com/a/43584000/15773786

The rewrite rule is relative to the path where the rewrite.config is placed in, so when it is placed in WEB-INF the url has to be adapted. In my case I had to cut the /mySpringApp part of the URL:

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/myAngularApp/(.*) /myAngularApp/index.html