Q:

how to consider modification time (mtime) by mod_rewrite

Is it possible to consider modification time (mtime) of file by mod_rewrite?
What I want to do is:

when accessed to '*.html':

return '*.html' when it exists and is newer than '*.html.eruby'.
rewrite into '*.html.eruby' when '*.html' doesn't exist or is older than '*.html.eruby'.

my .htaccess:
## inhibit direct access to *.eruby
RewriteRule \.eruby$ - [R=404,L]

## rewrite *.html into *.html.eruby when *.html.eruby exists
## (TODO: rewrite only when *.html.eruby is newer than *.html)
RewriteCond %{REQUEST_FILENAME}.eruby -s
RewriteRule ^(.*)$  $1.eruby

A:

Of course there's a solution. I sell it $100 000 000 (close friend's price). Just kidding.
To solve this, use RewriteMap directive that executes an external "filter". See here.
From the website, with emphasis on what you may look:

External Rewriting Program
MapType: prg, MapSource: Unix filesystem path to valid regular file Here the source is a program, not a map file. To create it you can
  use a language of your choice, but the result has to be an executable
  program (either object-code or a script with the magic cookie trick
  '#!/path/to/interpreter' as the first line).
This program is started once, when the Apache server is started, and
  then communicates with the rewriting engine via its stdin and stdout
  file-handles.

So my advice: make a very simple program in python that compares timestamps of the two files.
See here for a sample in Perl.

