Search code examples
websphereopen-liberty

Open Liberty 20.0.0 I need URL forwarding for context_root in server.xml


I am using an open liberty to deploy a war using the application tag in the server.xml. I am required to change the context_root for an application but I want the current context root to redirect to the new url. Alternatively, if it were possible, I could use two context roots for the same app. I cannot find the answer in their documentation.

<application id="demo" location = "demo-0.0.3-SNAPSHOT.war" name="demo" context-root="/test"></application>

What are my options here for making changing /test to /newroot where my.host/test will redirect to my.host/newurl from within the server.xml?


Solution

  • It is not possible to bind a single war file to two context roots. A few options would be:

    1. Deploy the application twice, once at each context root. This is probably not a good idea because you'll need double the resources.
    2. Use a web server in front and configure it to url rewrite before forwarding to Liberty
    3. Deploy a second war file bound to the old context root that has a servlet that sends a redirect to the new on.

    I would recommend upgrading to a newer release of Open Liberty since 20.0.0 is three years old now and there are a lot of fixes since then including security fixes.