Ok, so I wish to obtain a webapp running in tomcat (5.5) to operate behind apache 2 (2.2.3 more specifically) serving in the cause of the website (i.e. with no context), with static content being offered via apache.

Therefore if the application is running under "/myapp" on tomcat I wish to use apache (plus mod_rewrite) to really make it work as whether it's running under "/" rather.

Mod_jk is setup and dealing ok. I'm able to access the application from "/myapp", however i can't quite obtain the last bit working. Below may be the config I have got for mod_rewrite to understand this working. It properly will get rewrites /static/ web addresses to obtain apache for everyone them in the unpacked webapp and when I let the rewrite log I observe that it will attempt to feed other demands to /myapp via mod_jk. Nevertheless it appears that mod_jk isn't processing the request later on.



JkMount /myapp/*      worker1

RewriteEngine On

# ensure static stuff gets served by apache
RewriteRule ^/static/(.*)$ /var/lib/tomcat5.5/webapps/myapp/static/$1 [L]
# everything else should go through tomcat
RewriteRule ^/(.*)$ /myapp/$1 [L,PT]


When I have carried this out with apache 1 previously I have needed to make certain mod_jk get's loaded before mod_rewrite, however i can't appear to do this under apache 2. Any ideas? How can others usually do that?

Handled to obtain this working ultimately. It seems that I have to set a JkOption to:



JkOptions     +ForwardURICompat


After which mod_jk compares the rewritten URL. Must admit not 100% sure quite why this works, however i believe it's reverting for an older type of behavior. If anybody will easily notice us a better/more right way to do this I'd like to know.

Might be better use Apache for proxy rather than mod_jk. Something similar to this:

ProxyPass /static/ http://localhost:8080/myapp/static/

It may be simpler or even more transparent what goes on if you are using either Tomcat Virtual Hosts or different fittings for various hosts and merely deploy root programs (at "/") and setup Apache mod_jk sending towards the different fittings or virtual hosts.

Note: After I needed this I have labored with various fittings for various tomcat hosts or Engines (can't remember) and used ROOT programs. I have never attempted virtual hosts (title based) in tomcat, only speculating this perform.

Benefit: no path translation, thus a great deal simpler to know once make changes towards the installation several weeks after initial deployment.

I confess, it feels somewhat strange, but the advantage of readability may be worth a great deal to me.

We make use of the 'R' flag rather than 'PT':

RewriteRule ^/(.*)$ /myapp/$1 [L,R]

Edit: I skipped the purpose not to affect the URL the consumer sees. Another way would be to do:

JkMount /* worker1
JkUnmount /static/* worker1

Then you definitely won´t require the RewriteRule's.

And based on Apache Tomcat Site the brand new default configurations from the mod_jk are incompatible with mod_rewrite and you ought to use +ForwardURICompatUnparsed.