1

Tomcat : 8.5.30 Java 8 OS : macOS Mojave 10.14.6

As a sample project, I'm trying to redirect any url : /{dynamicValue}/entity/{entityID} to /entity/{dynamicValue}/entity/{entityID}. Here the 'entity' is my context and will be referencing entity.war inside the webapps directory.

Context File (Path : apache-tomcat-8.5.30/conf/context.xml):

<Context docBase="ROOT" path="/" reloadable="true" crossContext="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve"/>
</Context>

RewriteConfig File : (Path : apache-tomcat-8.5.30/webapps/ROOT/WEB_INF/rewrite.config.xml)

RewriteRule ^/(.*)/(.*)/(.*)$   $2/$1/$2/$3 [L,NE]

Exposed endpoint : /{dynamicValue}/entity/{entityID}

Internal Endpoint : /entity/{dynamicValue}/entity/{entityID}

Any call directly made to 'Internal Endpoint' works fine. But, API calls to 'Exposed Endpoint' are not being redirected to the 'Internal Endpoint'. (returning 404)

Any suggestions ?

Reference : Re-writing tomcat 8 urls

El Cid
  • 191
  • 1
  • 12
  • Your rewrite.config file is incorrectly named. – Siddharth Sharma Apr 28 '20 at 14:17
  • Oh that was weird. Saving and opening it in sublime added a *.xml extension at the end. Renamed and saved using terminal worked fine. Redirect is working as expected. Pls post your comment as answer and I'll accept it – El Cid Apr 28 '20 at 14:23

1 Answers1

1

Issue in rewrite.config file name.

Furthermore, Tomcat does not support dynamic/regex based contexts and that is because of well defined principles. If you have such a use case, I'd strongly advise figuring out the exact need for this and if you could improve the modelling.

Siddharth Sharma
  • 182
  • 1
  • 1
  • 10