Using tomcat, how do I get a request for http://www.mydomain.example to redirect to http://www.mydomain.example/somethingelse/index.jsp? I haven't even managed to get an index.html to display from http://mydomain.example.
-
is there a reason .htaccess or isapi would not work?Nona Urbiz– Nona Urbiz2009-09-01 17:15:54 +00:00Commented Sep 1, 2009 at 17:15
-
6@NonaUrbiz: isn't .htaccess Apache http server specific and does not work with Tomcat?Tim Büthe– Tim Büthe2011-11-16 16:05:32 +00:00Commented Nov 16, 2011 at 16:05
-
For anyone else Tomcat don't seem to recommend it see their docs - wiki.jenkins-ci.org/display/JENKINS/…KCD– KCD2013-03-26 22:03:17 +00:00Commented Mar 26, 2013 at 22:03
6 Answers
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.htmlor/index.jsp, and save.Remove
webapp/ROOT/index.html, if it exists.Create the file
webapp/ROOT/index.jspwith 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.
6 Comments
Name your webapp WAR “ROOT.war” or containing folder “ROOT”
1 Comment
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.
1 Comment
Tested and Working procedure:
Goto the file path
..\apache-tomcat-7.0.x\webapps\ROOT\index.jsp
remove the whole content or declare the below lines of code at the top of the index.jsp
<% response.sendRedirect("http://yourRedirectionURL"); %>
Please note that in jsp file you need to start the above line with <% and end with %>
Comments
What i did:
I added the following line inside of ROOT/index.jsp
<meta http-equiv="refresh" content="0;url=/somethingelse/index.jsp"/>
5 Comments
<% response.sendRedirect("/some/where"); %> and it works with HTTPS now.In Tomcat 8 you can also use the rewrite-valve
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/(.*)$ /somethingelse/index.jsp
To setup the rewrite-valve look here:
http://tonyjunkes.com/blog/a-brief-look-at-the-rewrite-valve-in-tomcat-8/