Apache .htaccess timestamp

apache-2.2cache

I'm trying to do some cache mechanism where I create cache files in php that have names like: test_page_20110122_23.html (test_page_[php date('Ymd_G)].html)

The plan is to serve these files without php, strictly by using only apache (or later nginx).
But in order to do that I have to write a rewrite rule that has the current date and time variables, eg:

RewriteCond /cache/%{REQUEST_FILENAME} _ {Ymd}{G}.html -f
RewriteRule ^(.*)$ /cache/$1
{Ymd}_{G}.html [L]

The only problem that I have is how to get these time variables in .htacces

Best Answer

You can do that in apache using mod_rewrite like this

RewriteCond /cache/%{REQUEST_FILENAME}_%{TIME_YEAR}%{TIME_MONTH}%{TIME_DAY}_%{TIME_HOUR}.html -f
RewriteRule ^(.*)$ /cache/$1_%{TIME_YEAR}%{TIME_MONTH}%{TIME_DAY}_%{TIME_HOUR}.html [L]