I have a Tomcat server, serving two .war
files. The first one is mapped to context /api
, the second one to root /
. The latter contains a single-page AngularJS app. It has the following web.xml
config:
<servlet>
<servlet-name>webapp</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
When I go to https://my.url/
, the index page of the single page app is properly served. So far, so good.
The problem is, when I deeplink to a page in my single page app, for example https://my.url/some/resource
, Tomcat will give a 404. Because of the error-page
config, it will still return the index page, but still with status 404. So, it kind of works, but not nicely.
Can I get Tomcat to return the index page with a proper 200 status code for all deep links? Of course, calls to /api
should still resolve to the other deployed .war
. I want to avoid duplicating the AngularJS url definitions in Tomcat, so it should just return the index page for any request that doesn't start with /api/
.