kotfu.net

Tomcat, Apache mod_jk and mod_rewrite

I have some tomcat apps with apache 2 in front of them, using mod_jk. Works great. I decided I wanted to use mod_rewrite (shudder) to make some friendlier URL's, you know instead of /some/path/command?var=value, have /some/path/command/value. Sounds great. Couldn't get it to work for anything. Found a howto at the Helma site, which had some good info, but he left out one very important thing.

Say I have a rule like:

RewriteRule ^(.*)/command/(.*)$ $1/command?var=$2 [QSA]

This is a basic rewrite to make friendlier URLS like I wanted. The QSA option allows me to muddle with the query string in my rule. When I use this rule, httpd doesn't do what I want it to. It rewrites the URL, then prepends the directory on disk that this container (apache VirtualHost or Directory keywords) points to. I want it to get processed by mod_jk instead.

After a few minutes I discovered the "PT" option. So if I change my rule to be:

RewriteRule ^(.*)/command/(.*)$ $1/command?var=$2 [PT,QSA]

the rewritten URL will be passed through to other handlers, like mod_jk.

Happiness. Finally.