Tomcat primary URL redirection

Using tomcat, how do I get a request from http://www.mydomain.com to redirect to http://www.mydomain.com/somethingelse/index.jsp ? I was not even able to get index.html to display from http://mydomain.com .

+52
html tomcat
Sep 01 '09 at 17:10
source share
5 answers

Name your webapp WAR "ROOT.war" or containing the folder "ROOT"

+19
Sep 01 '09 at 17:16
source share

You can do this: If your tomcat installation is the default and you have not made any changes, then the default war will be ROOT.war . That way, whenever you call http://yourserver.example.com/ , it will call index.html or index.jsp your default WAR file. Make the following changes to the webapp/ROOT folder to redirect requests to http://yourserver.example.com/somewhere/else :

  • Open webapp/ROOT/WEB-INF/web.xml , remove any servlet mapping using the path /index.html or /index.jsp , and save.

  • Remove webapp/ROOT/index.html if it exists.

  • Create the webapp/ROOT/index.jsp using this content line:

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

    or if you want to redirect to another server,

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

What is it.

+72
Sep 01 '09 at 17:56
source share

Take a look at UrlRewriteFilter , which is essentially a Java version of Apache mod_rewrite.

You need to extract it to the ROOT folder in the Tomcat webapps folder; You can configure redirects to any other context in your WEB-INF/urlrewrite.xml configuration file.

+17
Sep 01 '09 at 17:35
source share

What I've done:

I added the following line inside ROOT / index.jsp

  <meta http-equiv="refresh" content="0;url=/somethingelse/index.jsp"/> 
+8
Mar 20 2018-12-12T00:
source share

Tested and working procedure:

Go to the file path ..\apache-tomcat-7.0.x\webapps\ROOT\index.jsp

remove all content or declare below the line of code at the top of index.jsp

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

Note that in the jsp file you need to run the above line with <% and end with%>

+3
Jun 22 '16 at 13:07 on
source share



All Articles