mod_rewrite, RequestCond, File Age

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

In a nutshell, I have a cache system setup where mod_rewrite looks in a cache folder to see if the REQUEST_URI can be found there before rewriting the address and generating a page.

I'm looking for something, I'm guessing a RequestCond line, that would work with the age of the files in that cache directory too, not just whether it exists or not. Something along the lines of if REQUEST_URI is found in the /cache directory, and is less than 4 hours old, rewrite to that address, otherwise assume it doesn't exist and it will be overwritten by regeneration.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Looks like the answer is no.

I've scoured the web and Apaches manuals, it doesn't look good. closest thing I can find related to working with files, is the -f flag that tells you if it's an actual file, and the path of the file.

Guess I'll just continue to have cron jobs clean up the cache.
  • trevHCS
  • Novice
  • Novice
  • trevHCS
  • Posts: 34
  • Loc: NW England, UK

Post 3+ Months Ago

Don't know if any kindof fix is still valid, but I found this post while looking for the same thing, and essentially looks like the basic answer is mod_rewrite doesn't have the ability to look at file mod times.

However I did find a *kindof* workaround to this using an external bash script as documented in the address below (had to break it up to get past the spam checker system).

There is one problem - it seems you can't use rewritemap in .htaccess so this would only work on a dedicated server where you had access to the httpd.conf file. Looks like it can run in the virtual hosts bit, but is a bit of a pain.

http://stackoverflow.com/questions/1318 ... d-htaccess

Not tried the script, but I guess that or a PHP script could do the job. Right pain and stupid thing to leave out of .htaccess IMO.

Trev
Moderator Remark: Linkified URL
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

I've decided, for my situation, that it would be less work to have a cron job clean up the cache on a schedule than it would be to have each individual request do a lookup itself.

Nice link though. :D
  • trevHCS
  • Novice
  • Novice
  • trevHCS
  • Posts: 34
  • Loc: NW England, UK

Post 3+ Months Ago

Came to essentially the same conclusion myself, although using a backup of the cache too (incase of server problems). Pity that doesn't work as it should be pretty efficient since the rewritemap called script gets held in memory.

Trev

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.