Main Content

URL rewriting with front and back servers

Archive - Originally posted on "The Horse's Mouth" - 2008-12-14 06:16:32 - Graham Ellis

If you ask someone to double a number, they'll come back to you and tell you twice the number you gave them - give the "3" and they'll say "6". But if you tell them to double the number every time they handle it, but refer it to someone else for them to validate it, you'll get "12" back. Since they will double it each time they pass it on. And if the person they validated it with also doubles it, you'll get "24".

If you're calling up a web page from a Tomcat Server that's running an application behind an Httpd server, you need to make sure that your URLs don't get rewritten two or three times in this fashion - but rather they get processed each step along the way in such a fashion that the report back to the browser is the correct one. Using httpd's mod_proxy it is especially easy to get the rewriting wrong, though.

The diagram here shows each of the three steps where URL re-writing may happen with mod_proxy:
1. On the way in through httpd, as set up by the ProxyPass directive
2. At Tomcat, as defined by the proxyName and proxyPort attributes of the <Connector>
3. On the way back through httpd, as per the ProxyPassReverse directive

My own suggestion is to KISS ("Keep is Simple, Stupid!"). Leave off proxyName and proxyPort attributes on the Tomcat Connector, and have the ProxyPass and ProxyPassReverse set to be equal but opposite.