I have Apache in front of my Tomcat installation as a reverse proxy. Most URLs are routed to Tomcat by a JkMount
directive in Apache.
For one URL pattern I'd like Apache to route requests to the Tomcat worker only if a static asset isn't found on the filesystem.
Something roughly like this:
RewriteCond /var/www%{REQUEST_FILENAME} !-f
RewriteCond /var/www%{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^/assets/.*$
RewriteRule ^/(.*)$ http://${tomcat-ssl}/$1 [P] # This syntax is wrong
What syntax can I provide for the RewriteRule
to route the request to Tomcat?
The solution I found was to create an
Alias
, which Apache treats as a synonym for a give path. I created aRewriteRule
that rewrites the URL to thisAlias
if the file exists. Since theAlias
doesn't match theJkMount
, theJkMount
doesn't handle it. If the file doesn't exist, theRewriteCond
fails, theRewriteRule
isn't applied, and the request gets passed to Tomcat.