mod_rewrite, RequestCond, File Age

  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11879
  • Loc: Clearwater, FL
  • Status: Offline

Post September 27th, 2009, 1:29 pm

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.
Why yes, yes I am.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 27th, 2009, 1:29 pm

  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11879
  • Loc: Clearwater, FL
  • Status: Offline

Post September 27th, 2009, 4:41 pm

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.
Why yes, yes I am.
  • trevHCS
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Jun 14, 2005
  • Posts: 39
  • Loc: NW England, UK
  • Status: Offline

Post October 22nd, 2009, 8:38 am

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
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11879
  • Loc: Clearwater, FL
  • Status: Offline

Post October 22nd, 2009, 9:26 am

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
Why yes, yes I am.
  • trevHCS
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Jun 14, 2005
  • Posts: 39
  • Loc: NW England, UK
  • Status: Offline

Post October 22nd, 2009, 10:13 am

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 38 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
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.