1. I'm using a jetty server.
  2. I have a webapp running on: myip/myWebApp

Question: How to redirect base url to base url/something

ie. -->

So when a user hits my server will redirect to


Jetty has a Rewrite Handler that can be enabled using

$ java -jar start.jar --add-to-start=rewrite`

Following the examples given in the documentation, you can add a rule in the xml file:

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Ref refid="Rewrite">
    <Call name="addRule">
        <New class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
          <Set name="pattern" type="String"></Set>
          <Set name="location">/myWebApp/</Set>

The equivalent for embedded Jetty configuration file would be:

Server server = new Server();
RewriteHandler rewrite = new RewriteHandler();

RedirectPatternRule redirect = new RedirectPatternRule();

There may be a config based way to do this but a quick and dirty solution is to create an index page that redirects to the desired URL.

<html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="refresh" content="0;URL='/mywebapp'" />
  • Create a 'root' directory in jetty: mkdir /webapps/root
  • Create an index.html in /webapps/root/ with content like the above

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.