Tomcat base URL redirection
Using tomcat, how do I get a request for http://www.mydomain.com to redirect to http://www.mydomain.com/somethingelse/index.jsp ? i haven't even managed to get an index.html to display from http://mydomain.com.
将您的web应用命名为WAR“ROOT.war”或包含文件夹“ROOT”
You can do this: If your tomcat installation is default and you have not done any changes, then the default war will be ROOT.war . Thus whenever you will call http://yourserver.example.com/ , it will call the index.html or index.jsp of your default WAR file. Make the following changes in your webapp/ROOT folder for redirecting requests to http://yourserver.example.com/somewhere/else :
Open webapp/ROOT/WEB-INF/web.xml , remove any servlet mapping with path /index.html or /index.jsp , and save.
Remove webapp/ROOT/index.html , if it exists.
Create the file webapp/ROOT/index.jsp with this line of content:
<% response.sendRedirect("/some/where"); %>
or if you want to direct to a different server,
<% response.sendRedirect("http://otherserver.example.com/some/where"); %>
That's it.
Take a look at UrlRewriteFilter which is essentially a java-based implementation of Apache's mod_rewrite.
You'll need to extract it into ROOT folder under your Tomcat's webapps folder; you can then configure redirects to any other context within its WEB-INF/urlrewrite.xml configuration file.
下一篇: Tomcat基本URL重定向
