[英]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. 我们想要更改Tomcat Web应用程序的上下文根,并让旧URL引导用户访问新命名的应用程序。
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. 实现此目的的一种方法是使用newappname的上下文根和具有oldappname上下文根的另一个应用程序部署应用程序,并让用户引导用户访问新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). 这个简单的选项不对我们开放,内部公司策略阻止在同一个Tomcat实例中运行多个应用程序(不可协商)。
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 ? 我记得GlassFish有一个“备用文档根”的概念,可用于为应用程序提供多个上下文根,任何想法如何在Tomcat中执行此操作?
There is a Dir called ROOT
under tomcat/webapps
. 在tomcat/webapps
下有一个名为ROOT
的Dir。
This ROOT "app" ends up getting invoked for those URLs that have "contextPath" different from the Directories under Webapps folder. 对于那些“contextPath”与Webapps文件夹下的目录不同的URL,最终会调用此ROOT“app”。
So you could: 所以你可以:
Create folder called "oldappname" directly under the "ROOT" folder. 直接在“ROOT”文件夹下创建名为“oldappname”的文件夹。
Create an index.html in that "oldappname" folder, and make it have a Javascript to Redirect Browser to the new URL. 在该“oldappname”文件夹中创建一个index.html,并使其具有Javascript以将浏览器重定向到新URL。
Whenever the browser invokes http://servername/oldappname
, tomcat will render: webapps/ROOT/oldappname/index.html
每当浏览器调用http://servername/oldappname
,tomcat将呈现: webapps/ROOT/oldappname/index.html
UPDATE: 更新:
You could do some interesting things with ROOT: 你可以用ROOT做一些有趣的事情:
Tomcat 6: How to change the ROOT application Tomcat 6:如何更改ROOT应用程序
https://tomcat.apache.org/tomcat-7.0-doc/config/context.html https://tomcat.apache.org/tomcat-7.0-doc/config/context.html
An example of a index.html file to redirect from oldappname to newappname: 要从oldappname重定向到newappname的index.html文件的示例:
<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. 要放置在webapps/ROOT/oldappname
上面描述的webapps/ROOT/oldappname
中。
See also: How to set the context path of a web application in Tomcat 7.0 另请参阅: 如何在Tomcat 7.0中设置Web应用程序的上下文路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.