Tuesday, 29 July 2025

Redirect multiple application URL's deployed under Apache Tomcat


Requirement :

I want the perform below redirection 

http://apex.xxx.kw:8086/hr  ==to==>  http://apex.xxx.kw:8086/hr/f?p=101

http://apex.xxx.kw:8086/fin ==to==>  http://apex.xxx.kw:8086/fin/f?p=107

http://apex.xxx.kw:8086/tech ==to==>  http://apex.xxx.kw:8086/tech/f?p=217

Solution:

STEP 1 : Add below entry in server.xml

Just below the line
<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

add new line

<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />


STEP 2 : Define redirection rules

Under Tomcat\conf\Catalina\localhost create a file [ rewrite.config ] with below redirection entries.

# Redirect /hr to /hr/f?p=101 RewriteRule ^/hr/?$ /hr/f?p=102 [R=302,L] # Redirect /fin to /fin/f?p=107 RewriteRule ^/fin/?$ /fin/f?p=107 [R=302,L] # Redirect /tech to /tech/f?p=107 RewriteRule ^/tech/?$ /tech/f?p=107 [R=302,L] STEP 3 : Restart Apache Tomcat Services Below redirection is performed post restart of Apache Tomcat Services,

http://apex.xxx.kw:8086/hr ==to==>  http://apex.xxx.kw:8086/hr/f?p=101 http://apex.xxx.kw:8086/fin ==to==> http://apex.xxx.kw:8086/fin/f?p=107 http://apex.xxx.kw:8086/tech ==to==> http://apex.xxx.kw:8086/tech/f?p=217

Note*****
If you have single URL, you can simply update the index.php file under webapps\ROOT directory and define the redirection rule there.

No comments:

Post a Comment