Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat - redirect old context root to new context root

We want to change the context root of a Tomcat web appplication and have the old URL guide users to the newly named application.

http://hostname/oldappname
http://hostname/newappname

One way to do this would be deploy the application with a context root of newappname and another application with a context root of oldappname and have it guide users to the new URL.

This simple option is not open to us, internal company policy prevents the running of multiple applications in the same instance of Tomcat (not negotiable).

I remember GlassFish has the concept of an "Alternate document root" that could be used to give an application multiple context roots, any idea how to do this in Tomcat ?

like image 339
user835745 Avatar asked May 27 '15 18:05

user835745


People also ask

How do you change the context of a root?

1.1 Right click on the project, select Properties , Web Project Settings , update the context root here. 1.2 Remove your web app from the server and add it back. The context root should be updated. 1.3 If step 2 is failing, delete the server, create a new server and add back the web app.

What is docBase in Tomcat context?

The docBase attribute is a path to the WAR file or exploded deployment directory. It is relative to the webapps directory, although an absolute path can be used. The path attribute is the one we are most interested in, as it defines the context path of the application.


1 Answers

There is a Dir called ROOT under tomcat/webapps.

This ROOT "app" ends up getting invoked for those URLs that have "contextPath" different from the Directories under Webapps folder.

So you could:

  1. Create folder called "oldappname" directly under the "ROOT" folder.

  2. Create an index.html in that "oldappname" folder, and make it have a Javascript to Redirect Browser to the new URL.

Whenever the browser invokes http://servername/oldappname , tomcat will render: webapps/ROOT/oldappname/index.html

UPDATE:

You could do some interesting things with ROOT:

Tomcat 6: How to change the ROOT application

https://tomcat.apache.org/tomcat-7.0-doc/config/context.html

like image 179
Mecon Avatar answered Sep 22 '22 16:09

Mecon