Brain Dump

A place to store my random thoughts and anything else I might find useful.

Redirecting tomcat ROOT

Posted by mzanfardino on November 7, 2008

The goal is to force tomcat to redirect the default root homepage to another page altogether. With Apache2 it’s a simple matter of adding some code to apache2.conf

Redirect /index.html http://$server/$path/index.html

Where $server and $path represent the server and path to redirect.

This does not appear to be the case with Tomcat, or if it is, I can’t seem to find the right file to update in order to make this change. However, I did find a really good tip from another on how to override the default home page (source sited below).

Essentially when Tomcat is installed it’s configured to look for index.html, index.htm, and index.jsp in $TOMCAT_HOME/webapps/ROOT. (which for my system is /usr/local/tomcat/webapps/ROOT). The index.jsp file located there is the administrator welcome page that is displayed by default. Simply creating an index.html page will override the jsp as the html is loaded before the jsp according to the configuration file located in $TOMCAT_HOME/conf/web.xml. The files and their order is defined in <welcome-file-list>.

The index.html needs to be quite simple and should look as follows:

<html>
  <head>
    <meta http-equiv="refresh" content="0;URL=http[s]://$server/$path/index.html">
  </head>
  <body>
  </body>
</html>

This to me does not appear to be the ideal solution, as it forces the server to perform another round trip, which is inefficient particularly if you are redirecting to the same server but to a different application. However, until I can find a more proper solution such as the apache2 solution, this will have to be what I use.

Source: Tomcat Wiki

3 Responses to “Redirecting tomcat ROOT”

  1. Mahesh said

    Thank you, its elegant and easy to implement.

  2. […] users to see at root.  I want them to see my application.  So I borrowed some instructions from this blog to make that root directory point […]

  3. Marium said

    thank you…its really easy to implement.

Leave a comment