ProxyPass only if file doesn't exist

I've seen this example:

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://app_cluster%{REQUEST_URI} [P,QSA,L]

I need a similar thing that will delegate to mod_proxy (i.e. do a ProxyPass) when a static file does not exist. Is it doable?


This setup with the P flag is the right one for what you want to do. The doc about the P flag states:

Use this flag (P) to achieve a more powerful implementation of the ProxyPass directive

Some things about the example: as mentioned by Andrew in his answer, the DOCUMENT_ROOT is not necessary.

The second is just to pay attention where these instructions are located: remove the first "/" of the RewriteRule (^(.*)$) if you put this in a or similar container...

And the P flag implies the L flag, so it is not used but may make it a bit clearer if we leave it. There is also a "/" needed after the web addres.

So it may become something like:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://somewhere/$1 [P,QSA,L]