[wp-hackers] needs testing and feedback: small patch for nice permalinks on lighttpd

Michel Valdrighi michelv at gmail.com
Tue Mar 15 17:59:00 GMT 2005


Hello,

It just happens that lighttpd does not support rewrite rules the Apache way.
Instead, you have to input them in lighttpd.conf, but at least their
syntax is about the same.

So here's the kicker: most WP installs have permalinks starting with
/string/, where 'string' is generally 'archives' and will be
'archives' just for the sake of this example.
>From there, we can safely say that if we redirect /string/ to
/index.php/archives/, we can take advantage of WP's handling of
PATH_INFO.

So in lighttpd, I added this line:
url.rewrite = ( "^/archives/(.+)$" => "/index.php/archives/$1" )

All is well, no 404 anymore, but then again PATH_INFO is empty with
this method alone so index.php is called with no args.
A quick look in $_SERVER reveals a REDIRECT_URI element that holds
what would otherwise be in PATH_INFO. A look at wp-blog-header.php
shows all we need is to trigger parsing of REQUEST_URI by adding a
condition for the execution of the right block of code.
(REDIRECT_URI is only set when the URI got rewritten by lighttpd.)

So here's this patch:

Index: wp-blog-header.php
===================================================================
--- wp-blog-header.php  (revision 2429)
+++ wp-blog-header.php  (working copy)
@@ -18,8 +18,9 @@
                ((! empty($_SERVER['PATH_INFO'])) &&
                ('/' != $_SERVER['PATH_INFO']) &&
                 (false === strpos($_SERVER['PATH_INFO'], '.php'))
+               ) ||
+               (('' == $_SERVER['PATH_INFO']) &&
(isset($_SERVER['REDIRECT_URI']))
                )) {
-
        // If we match a rewrite rule, this will be cleared.
        $error = '404';
 
Voilà, archives load right from /archives/ ! :)

Anyone brave enough to test this patch and the rewrite rule with an
install of WP on lighttpd?
I'm also curious about any wrong assumptions I may have with this
patch, and lighttpd's behaviour. It just seems too easy to not hide a
catch.

-- 
Michel Valdrighi
Devéloppeur Web Intraordinaire
http://zengun.org/weblog/


More information about the wp-hackers mailing list