redirect - Forward requests and headers to different host using tomcat -
i have stand-alone tomcat server (no apache/nginx in front) need configure reroute incoming requests and headers specific application different host. in other words, need url
https://host.company.com/app/<anything here after>
redirected to
https://newhost.company.com/app/<anything here after>
such that
https://host.company.com/app/v1/explore?id=foo&pw=bar&more=crap
is redirected to
https://newhost.company.com/app/v1/explore?id=foo&pw=bar&more=crap
while not interfering https://host.company.com/app2
or https://host.company.com/app3
.
currently, have urlrewrite installed in webapps/app
so:
webapps/app/web-inf/urlrewrite.xml:
<?xml version="1.0" encoding="utf-8"?> <!doctype urlrewrite public "-//tuckey.org//dtd urlrewrite 4.0//en" "https://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"> <urlrewrite> <rule> <name>requests /app/ redirected https://newhost.company.com/app/</name> <from>^/(.*)$</from> <to type="permanent-redirect" last="true">https://newhost.company.com/app/$1</to> </rule> </urlrewrite>
webapps/app/web-inf/web.xml:
<filter> <filter-name>urlrewritefilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.urlrewritefilter</filter-class> </filter> <filter-mapping> <filter-name>urlrewritefilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>request</dispatcher> <dispatcher>forward</dispatcher> </filter-mapping>
the redirect https://newhost.company.com
working, headers not forwarded, , key element in making work. while works fine:
curl --compressed -h 'accept-encoding:gzip' --get 'https://newhost.company.com/app/v1/explore' --data-urlencode 'id=foo' --data-urlencode 'pw=bar' --data-urlencode 'more=crap'
this not
curl --compressed -h 'accept-encoding:gzip' --get 'https://host.company.com/app/v1/explore' --data-urlencode 'id=foo' --data-urlencode 'pw=bar' --data-urlencode 'more=crap'
and running above -vv
reveals issue (stripped down clarity):
* connected host.company.com (w.x.y.z) port 443 (#0) > /app/v1/explore?id=foo&pw=bar&more=crap http/1.1 < http/1.1 301 moved permanently < location: https://newhost.company.com/app/v1/explore * connected newhost.company.com (w.x.y.z) port 443 (#1) > /app/v1/explore http/1.1
as can see, newhost.company.com doesn't include uri data starting '?'. when using standard browser, resulting url https://newhost.company.com/app/v1/explore
makes sense given above. however, need uri data passed onto newhost.company.com, , don't know how tomcat it.
note: putting apache/nginx/etc in front of tomcat not option "security" purposes (not requirement, edict management)
when using urlrewrite need add use-query-string="true" urlrewrite.xml urlrewrite tag pass through query string parameters on forwarded url.
change from:
<urlrewrite>
change to:
<urlrewrite use-query-string="true">
Comments
Post a Comment