regex - Re-writing tomcat 8 urls -
i have 2 tomcat applications deployed under 2 different contexts:
someurl.com/context1/ someurl.com/context2/
i need intercept urls in form:
someurl.com/clientname/context1/
and redirect them url:
someurl.com/context1/clientname
where "clientname" dynamic
i have tried using rewrite valve in element of tomcats server.xml file, still works urls include context. i.e.:
someurl.com/context1/clientname/context1
gets re-written to
someurl.com/context1/clientname
using following regex:
rewritecond %{request_uri} ^.*/context1/.*$ rewriterule ^.*/context1/(.*)$ /context1/$1 [l]
is there way globally re-write urls in such way context not taken account?
after lot of digging around found out easy way of achieving desired result. trick set root context without actual application being deployed there. root context rewritevalve added this:
<?xml version='1.0' encoding='utf-8'?> <context docbase="root" path="/" reloadable="true" crosscontext="true"> <valve classname="org.apache.catalina.valves.rewrite.rewritevalve"/> </context>
it important crosscontext set true, root context can communicate lower level contexts.
then in web-inf of root context following rewrite.config trick:
rewriterule ^/.*/context1/(.*)$ /context1/$1 [l]
which means: capture ur's have form: clientname/context1/etc , route them context1/clientname/etc
Comments
Post a Comment