6

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 ?

Mecon
  • 977
  • 1
  • 6
  • 17
user835745
  • 1,974
  • 3
  • 17
  • 18

2 Answers2

5

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

Community
  • 1
  • 1
Mecon
  • 977
  • 1
  • 6
  • 17
  • Hello Mecon, thank you, I've tried your suggestion, it works beautifully and I might use. I was hoping to find something that is all contained in one war file. Perhaps that is not possible. – user835745 Jun 01 '15 at 15:15
  • If you are being restricted from running multiple applications on a one Tomcat, then you should ask them to let you deploy your application as the Root App. .. But that might need you to change the URIs in your code. – Mecon Jun 01 '15 at 15:22
  • Tell them that we need to control the ROOT app because right now ROOT dir has unauthorized code (i.e. Tomcat examples). – Mecon Jun 01 '15 at 15:24
  • @user835745 how's it going with this issue? I hope above suggestions helped? – Mecon Jun 19 '15 at 16:55
1

An example of a index.html file to redirect from oldappname to newappname:

<html>
<head>
<script type="text/javascript">
window.location.href = "/newappname";
</script>
</head>
</html>

To be placed in webapps/ROOT/oldappname as desribed above by Mecon.

See also: How to set the context path of a web application in Tomcat 7.0

stacker
  • 68,052
  • 28
  • 140
  • 210