Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to always return index.html Tomcat

I have an Angular application running live on Tomcat, but since I have implemented routing, if I visit a url manually I get a 404 not found. Also when an error occurs, it's a basic server page, not my error url page.

How do I configure Tomcat to always return index.html on routing and on errors? I know the set up, as I have done it with a different server, I'm just new to Tomcat and couldn't find anything online.

From my understanding, it's a pretty straightforward few lines of code in other back-end languages, I just can't find any info on Tomcat.

like image 611
FussinHussin Avatar asked Feb 01 '26 04:02

FussinHussin


1 Answers

Basically you have to change web.xml file inside conf folder of the Tomcat directory: $CATALINA_HOME/conf/web.xml.

<error-page> 
    <error-code>404</error-code>
    <location>/error/index.html</location>
</error-page>

And add a webapp that has the page and will answer to the URL under given location.

like image 105
Rohan Kadu Avatar answered Feb 02 '26 16:02

Rohan Kadu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!