Hack: Getting Lessn to Work on lighttpd

Over the weekend I decided to bite the bullet and move my domains from an Apache setup with Slicehost over to a peppier lighttpd server with Linode. All of my web apps transitioned to the new configuration easily (including WordPress) with a little lighttpd.conf magic, but I had a hard time getting Lessn to work nicely. I tried url.rewrites and url.redirects in all sorts of combinations, but was never able to find a solution for passing the token variable directly. Ultimately I decided to go an easier route and put in a minor hack into Lessn itself.

First, here’s what the related portion of my lighttpd.conf file looks like. We’re just replicating what Lessn’s own .htaccess file tells Apache to do.

$HTTP["url"] =~ "^/g/-/" {
	server.error-handler-404 = "/g/-/index.php"
}
$HTTP["url"] =~ "^/g/" {
	server.error-handler-404 = "/g/index.php"
}

Important – I have my Lessn installation located at /g, so you’ll want to tweak these rules to match wherever you installed yours.

Now open up Lessn’s /index.php. Beneath the includes we’ll be adding a few lines to grab the token from the request uri, like so:

include('-/config.php');
include('-/db.php');

if(!isset($_GET['token'])) {
	if(isset($_SERVER['REQUEST_URI'])) {
		$_GET['token'] = substr($_SERVER['REQUEST_URI'],
					strrpos($_SERVER['REQUEST_URI'], '/') + 1);
	}
}

There you go: a functioning instance of Lessn on lighttpd. Enjoy.

Tags: , ,

Leave a comment

blog comments powered by Disqus