2009-09-01 114 views
53

使用tomcat,我如何获得请求http://www.mydomain.com重定向到http://www.mydomain.com/somethingelse/index.jsp?我甚至没有设法从http://mydomain.com获得index.html显示。Tomcat基本URL重定向

+0

结束是有原因的.htaccess或ISAPI是行不通的? – 2009-09-01 17:15:54

+4

@NonaUrbiz:是不是.htaccess的Apache HTTP服务器的具体和不工作与Tomcat? – 2011-11-16 16:05:32

+0

对于任何其他Tomcat似乎不推荐它看到他们的文档 - https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache – KCD 2013-03-26 22:03:17

回答

19

名称你的web应用WAR“ROOT.war”或包含文件夹“ROOT”

17

看看UrlRewriteFilter基本上是Apache的mod_rewrite的基于Java的实现。

您需要将它解压缩到您的Tomcat的webapps文件夹下的ROOT文件夹;然后可以将重定向配置为其WEB-INF/urlrewrite.xml配置文件中的任何其他上下文。

+0

UrlRewriteFilter速度很快,对我来说效果很好。 [手册](http://urlrewritefilter.googlecode。com/svn/trunk/src/doc/manual/4.0/index.html)有一些很好的选择和[这篇博文](http://nematodes.org/martin/2010/02/04/301-permanent-redirect -with-tomcat-howto /)也有一些很好的信息。 – cwd 2013-05-02 23:05:06

76

你可以这样做: 如果你的tomcat安装是默认的并且你没有做任何改变,那么默认的战争将是ROOT.war。因此,只要您拨打http://yourserver.example.com/,它就会调用默认WAR文件的index.htmlindex.jsp。使你的webapp/ROOT文件夹中的以下更改为将请求重定向到http://yourserver.example.com/somewhere/else

  1. 打开webapp/ROOT/WEB-INF/web.xml, 删除任何servlet映射与路径/index.html/index.jsp, 和保存。

  2. 删除webapp/ROOT/index.html,如果存在。

  3. 这一行的内容创建文件webapp/ROOT/index.jsp

    <% response.sendRedirect("/some/where"); %> 
    

    ,或者如果你想直接到不同的服务器,

    <% response.sendRedirect("http://otherserver.example.com/some/where"); %> 
    

就是这样。

+7

只需要第二步。测试了Tomcat 7. – dustmachine 2011-10-07 22:06:00

+11

sendRedirect命令是我所需要的。 index.jsp只包含: <% response.sendRedirect(“/ jasperserver”); %> – 2013-01-11 11:20:17

+2

不要忘记在任何jsp scriptlet之前加上<% and %> – 2014-06-14 12:10:26

8

我做了什么:

添加以下行ROOT内部/ index.jsp的

<meta http-equiv="refresh" content="0;url=/somethingelse/index.jsp"/> 
+2

这可能真的搞砸了你的分析数据,因为推介将会丢失。 – sbichenko 2015-08-31 10:21:07

+0

这会起作用,但不是这样做的。 – AdrianRM 2015-11-06 15:19:00

+0

这种方法的一个小好处是它可以进入index.html而不是index.jsp – Edd 2016-02-23 16:34:05

5

测试和工作程序:

转到文件路径 ..\apache-tomcat-7.0.x\webapps\ROOT\index.jsp

删除整个内容或在index.jsp的顶部声明以下代码行

<% response.sendRedirect("http://yourRedirectionURL"); %>

请注意,在JSP文件中,你需要用<%开始以上线与%>