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
.

- 23,933
- 14
- 88
- 109

- 15,477
- 19
- 69
- 94
-
is there a reason .htaccess or isapi would not work? – Nona Urbiz Sep 01 '09 at 17:15
-
6@NonaUrbiz: isn't .htaccess Apache http server specific and does not work with Tomcat? – Tim Büthe Nov 16 '11 at 16:05
-
For anyone else Tomcat don't seem to recommend it see their docs - https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache – KCD Mar 26 '13 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.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.

- 8,425
- 1
- 38
- 70

- 8,506
- 3
- 32
- 29
-
9
-
11The sendRedirect command was all that was needed for me. index.jsp just contains: <% response.sendRedirect("/jasperserver"); %> – Andy Burton Jan 11 '13 at 11:20
-
3
-
-
Java wasn't working for me, so I used index.html with html redirection. https://stackoverflow.com/questions/5411538/redirect-from-an-html-page – Dec 08 '17 at 13:10
-
If you need to include query parameters, you can do something like this: `<% response.sendRedirect(request.getQueryString()!=null ? ("/some/where?" + request.getQueryString()) : "/some/where"); %>` – anztenney Apr 03 '18 at 14:58
Name your webapp WAR “ROOT.war” or containing folder “ROOT”

- 261,858
- 191
- 397
- 503
-
2This approach causes a lot of problems when working on local and then deploying your application to multiple servers. Specially if you have multiple projects going to be deployed on different servers, and each can be ROOT on their own servers. – zookastos Aug 20 '19 at 15:49
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.

- 99,456
- 24
- 206
- 195
-
UrlRewriteFilter is fast and worked well for me. [the manual](http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html) has some great options and [this blog post](http://nematodes.org/martin/2010/02/04/301-permanent-redirect-with-tomcat-howto/) also has some good info. – cwd May 02 '13 at 23:05
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 %>
What i did:
I added the following line inside of ROOT/index.jsp
<meta http-equiv="refresh" content="0;url=/somethingelse/index.jsp"/>

- 451
- 6
- 13
-
2This might really screw up your analytics data, since the referral will be lost. – Stas Bichenko Aug 31 '15 at 10:21
-
1One small benefit of this method is it can go in index.html instead of index.jsp – Edd Feb 23 '16 at 16:34
-
-
Viral Patel's and ChssPly76's are both valid answers: http://stackoverflow.com/a/1363781/208576 http://stackoverflow.com/a/1363685/208576 – AdrianRM Jun 24 '16 at 16:40
-
This worked for me until I have enabled HTTPS. Switched to `<% response.sendRedirect("/some/where"); %>` and it works with HTTPS now. – Michał Maciej Gałuszka Apr 26 '18 at 13:50
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/

- 374
- 3
- 12