url.rewrite-if-not-file - check for multiple files?

Added by Albright about 9 years ago

I'm trying to create the analogue to this in a Lighty .conf file:

  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.xml [L,T=text/xml]
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.json -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.json [L,T=text/javascript]

So if is requested, this is basically saying…

  1. If cache/normal/ exists, serve it.
  2. If cache/normal/ exists, serve it.
  3. If cache/normal/ exists, serve it.

However, with url.rewrite-if-not-file, it does not seem to be possible to check for the existence of more than one file. My approach so far has been:

$HTTP["host"] =~ "(.*)" {
  url.rewrite-if-not-file = (
    "^/(?!\.(html|xml|json))(.*)" => "/cache/normal/%1/$1_.html",
    "^/cache/normal(.*)\.html$" => "/cache/normal$1.xml",
    "^/cache/normal(.*)\.xml$" => "/cache/normal$1.json" 
(This ignores the query string part for the moment.) I was hoping this would have the same effect; however, the effect seems to be that only cache/normal/ is checked for. If that's not found, it doesn't check for cache/normal/ and so on.

I tried using url.rewrite-repeat-if-not-file, but that doesn't check for the file existence between every rewrite either; the end result seems to be that only cache/normal/ is checked for (as the rewriting is happening on every step).

Is there a way to check for multiple files this way?

Yes, I know it can be done in Lua, and that's how we're currently doing it. I was hoping we could do it while ditching Lua, though, both for speed and for the ability to use more powerful RegEx than Lua's pattern matching supports.

(For the curious: I'm trying to enable the Boost module ( ) for the Drupal CMS. Here's how I did it in Lua: )