Tomcat base URL redirection

HtmlTomcat

Html Problem Overview


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.

Html Solutions


Solution 1 - Html

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:

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

  2. Remove webapp/ROOT/index.html, if it exists.

  3. 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.

Solution 2 - Html

Name your webapp WAR “ROOT.war” or containing folder “ROOT”

Solution 3 - Html

Take a look at http://tuckey.org/urlrewrite/">UrlRewriteFilter</a> 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.

Solution 4 - Html

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 %>

Solution 5 - Html

What i did:

I added the following line inside

of ROOT/index.jsp

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

Solution 6 - Html

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/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNathaniel FlathView Question on Stackoverflow
Solution 1 - HtmlViral PatelView Answer on Stackoverflow
Solution 2 - HtmlflybywireView Answer on Stackoverflow
Solution 3 - HtmlChssPly76View Answer on Stackoverflow
Solution 4 - HtmlobaidView Answer on Stackoverflow
Solution 5 - HtmlKevinView Answer on Stackoverflow
Solution 6 - HtmlprogressdllView Answer on Stackoverflow