Ian Bicking: the old part of his blog

Static Caching with mod_rewrite

I put a static cache of my Ruby/Python post since it's been pretty popular and this blog software is very slow (among many of its flaws). I got it wrong at first and made it static regardless of what you tried to do, which mean that commenting was also broken (so that's why commenting stopped...). Anyway, here's the rule I ended up with:

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond /home/blog/static_cache/%{REQUEST_URI} -s
RewriteRule (.*\.html)$ /home/blog/static_cache$1 [L]

The idea is that only when there's no GET variables (the first rule), it is a GET request (not a POST; second rule), and file with that name exists on disk (third rule), then serve up that file, assuming it ends with .html. (Incidentally, mod_rewrite actually applies the RewriteRule first, then applies the conditionals)

Then I have a cron job that runs this script periodically:

cd /home/blog/static_cache
for F in `cat /home/blog/static_cache_files.txt` ; do
  wget -q -O $F "https://ianbicking.org/$F?nocache"
done
Created 31 Aug '05

Comments:

Better would be to replace it with something faster. And something that has anti-spam-protection features... These spams are really annoying!

# Mike

Yeah, yeah, that would require much more effort. It's so hard to convert these damn things.

I also like threaded discussion, which is extremely uncommon in blogging software. I think there's been some really good discussion in the comments on this blog, and that is much more manageable for all involved because of threading.

But yeah, the spam and crashing aren't fun :(

# Ian Bicking

Also the availability of this site wasn't the best in the past...

# Mike