0

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?

1 Answer 1

0

The solution I found was to create an Alias, which Apache treats as a synonym for a give path. I created a RewriteRule that rewrites the URL to this Alias if the file exists. Since the Alias doesn't match the JkMount, the JkMount doesn't handle it. If the file doesn't exist, the RewriteCond fails, the RewriteRule isn't applied, and the request gets passed to Tomcat.

Alias /localstaticassets /var/www/assets                                                                                                                                                                                                     
RewriteCond /var/www/%{REQUEST_FILENAME} -f                                                                                                                                                                                                  
RewriteRule ^/assets/(.*)$ /localstaticassets/$1 [QSA,PT]

JkMount /assets/* tomcat-ssl

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .