Hack of the Year

As you might have noticed, I’ve switched back to using WordPress (again), and managed to dig up all my old blog posts (most of which are utter crap). At the moment I’m using the lighttpd web server, and I had to play around a bit with mod_rewrite in order to get the pretty URLs working. In the end I got lazy and just settled for a hack I found on the Internet. And as a hack, it’s pretty epic.

server.error-handler-404 = "/index.php?error=404"

What it does is thus: when you click on a page in the blog (such as http://www.jackscott.id.au/2009/04/hack-of-the-year), it searches for a folder named 2009 on my web server. That doesn’t exist, so it produces an HTTP 404 error (which means the page doesn’t exist). The rule above (pasted into the lighttpd configuration file) redirects all 404 errors to the index.php file. And this file (as the WordPress main file) just happens to know where to find the page requested. Truly a monumental hack.

The only downside to using this configuration is that Statpress (my favourite WordPress plugin) no longer works properly. It reports the correct number of page views and so on, but all pages requested are listed as ‘error=404‘. Not very useful when you want to see which pages are viewed the most.

But nevertheless, a pretty cool thing.

Liked this? Here's some more:

  • No Related Posts! How sad!

3 thoughts on “Hack of the Year”

  1. As an update, I’ve just been given the correct mod-rewrite rules for lighttpd by my friend Michael.

    url.rewrite-final = (
    "^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
    "^/(.*\.php)" => "$0",
    "^/(.*)$" => "/index.php/$1"
  2. Actually, it’s not that bad as it sounds.
    This is the way how static pages work in django – when 404 is raised, except statement catches it & checks the URL against the list of static pages

  3. I wouldn’t mind at all that this is the way it works, it’s wonderful, except that Statpress no longer works properly. And I like my Statpress. 🙂

Comments are closed.