Wednesday 09 August 2006 by
I was setting up a textpattern install on the lighttpd-webserver a few days ago. To achieve clean urls the server.error-handler-404 directive can be used. Lighttpd doesn’t have the same problems as apache with POST data, so comments etc. will just work with this method.
However it has another problem as described in their FAQ item:
The environment (which is relevant when using CGI or FastCGI) is quite normal, but observe the following: [..] QUERY_STRING is not set, so you have to parse the REQUEST_URI yourself to get it. [...]
This affects only very few things, things like category-filters which sometimes can use query strings. And probably a few plugins use that method as well. The fix is easy enough though. Just add this to a plugin you have (or create a new plugin):
if (@txpinterface == 'public')
register_callback("asy_fix_querystring", "pretext");
function asy_fix_querystring($event, $step) {
if (!strstr($_SERVER['REQUEST_URI'],'?') or !empty($_GET)) return;
$_SERVER['QUERY_STRING'] = preg_replace('#^.*?\?#','',$_SERVER['REQUEST_URI']);
parse_str($_SERVER['QUERY_STRING'], $_GET);
}
That’s it. Now $_GET and $_SERVER['QUERY_STRING'] should be as expected.
Should have used
parse_url($_SERVER['REQUEST_URI'])['query']instead of the regular expression…
09 Aug 06
Scott
Ah, I could have.
Seems there is really a function for everything in PHP. :)
09 Aug 06
Sencer
Oooh… thanks for this, Sencer. I’ve been using messy URLs on lighttpd, but now I can breathe a clean sigh of relief!
09 Aug 06
Andrew Ho
Big, big thanks. This patch is still (lighttpd 1.4.25) up to date.
13 Jan 10
Andreas