Nov 4, 2017

How to redirect URL in Glassfish / Payara Java EE server

In the admin panel, navigate to :
Configuration, HTTP Service, Virtual Servers, server
Scroll to bottom of page :
Add Property
Name :
redirect_i88ca
( for the name, it should be "redirect_****", ie, always start with "redirect_", and then you can append other characters)

Value :
from=/{name of webapp to redirect} url={URL to redirect traffic to}

For example :
from=/myApp url=http://www.i88.ca

Click ‘Save’ button.

You can do:

from=/myApp/myPath url=http://www.i88.ca/myPath2

too.

And request parameters are redirected too.

The above only redirects to a specific address, to redirect with subfolder, for example:

/myApp/myPah1 to http://it.i88.ca/myPath1
/myApp/myPath2 to http://it.i88.ca/myPath2

then use url-prefix instead:

from=/myApp url-prefix=http://www.i88.ca

This redirect only works for HTTP method GET, it doesn't work for HTTP method POST.

Directly in domain.xml:


<virtual-server hosts="${com.sun.aas.hostName}" http-listeners="http-listener-1,http-listener-2" id="server" log-file="${com.sun.aas.instanceRoot}/logs/server.log" state="on">
          <property name="docroot" value="${com.sun.aas.instanceRoot}/docroot"/>
          <property name="accesslog" value="${com.sun.aas.instanceRoot}/logs/access"/>
          <property name="sso-enabled" value="false"/>
          <property name="allowLinking" value="true"/>
          <property name="redirect_i" value="from=/i88/ca.html url=http://it.i88.ca"/>
</virtual-server>

For url-prefix,
<property name="redirect_i" value="from=/i88 url-prefix=http://it.i88.ca/i88"/>

will redirect http://current-host/i88?id=88 to http://it.i88.ca/i88/?id=88

<property name="redirect_i" value="from=/i88/ url-prefix=http://it.i88.ca/i88"/>

will correctly redirect http://current-host/i88?id=88 to http://it.i88.ca/i88?id=88