Lighttpd 1.5 rewrite rules for WordPress
GreatWebGuy.com is now running on Lighttpd or "Lighty" 1.5 and WordPress 2.2. The biggest hurdle we had to overcome running our blog with the Lighty http server was the rewrite rules for our custom Permalink structure - /%category%/%postname%/ - none of the rewrite rules posted on the web seemed to work correctly. If you get the rules right, you should be able to accomplish the pretty urls that you want with 5 or fewer rewrite rules, I've seen some examples on the web with as few as 4 and as many as 30. We also ran into problems with the version numbers included in the querystring of the internal javascript urls in WordPress, it turned out they were being rewritten unintentionally.
These may work or not for your setup, a couple of things to note when writing rewrite rules:
- Start your rule set with areas you know need to be excluded, not rewritten, and write rules that result in => "$0"
- Work your way from specific rules to more generic and all encompassing rules
- Attempt to break the rules down into as few rules as possible, realize rule interpretation causes load on the http server
- Use rewrite-once so that Lighty will stop processing rules when it's found a match
url.rewrite-once = ( "^/(wp-.+).*/?" => "$0", "^/(sitemap.xml)" => "$0", "^/(xmlrpc.php)" => "$0", "^/keyword/([A-Za-z_0-9\-]+)/?$" => "/index.php?keyword=$1", "^/.*?(\?.*)?$" => "/index.php$1" )
September 29th, 2007 - 06:30
Thanks, the rules works (with some small changes) on lighttpd 1.4.x but i cant’t post comments on my form. I think this is some permalink-issue. Can you help me?
August 14th, 2008 - 11:41
Yeah, working perfectly. Thanks!
August 14th, 2008 - 19:12
Glad to hear it, I was beginning to think nobody else was running lighttpd, but me.
September 10th, 2008 - 15:25
cool~~it works well~~thx
September 15th, 2008 - 05:39
The way I use lighttpd with WordPress’ permalinks is simply set server.error-handler-404 to WP’s index.php file — this is on 1.4, by the way.
September 24th, 2008 - 05:12
well i cant make it on lighty with the rewrite rule you wrote here
September 24th, 2008 - 06:10
@mwunm sorry to hear that, these are specific to lighty 1.5 and will only work with the permalink structure that I’ve chosen to use,/%category%/%postname%/. I’m now on WordPress 2.6.2 and the rules are still working great. Hope you find a solution that works for you.
December 25th, 2008 - 15:29
Just to say, much thanks
And i can confirm that this works perfectly with wp 2.7!
June 17th, 2009 - 13:45
@Bas: This post fills in the details on that technique: http://r00tshell.com/archives/2007/05/16/wordpress-lighttpd-permalinks-without-rewrite/. I’ve seen about ten different approaches to this problem so far, but is the cleverest and simplest, and it looks like it solves other problems as well. Working great for me so far.
April 24th, 2010 - 05:23
Thank you, works like a charme. I added some lines of code that help to keep your lighttpd.conf clean in case of many wordpress installations on one server: http://www.chrische.de/2010/04/lighttpd-in-verbindung-mit-wordpress-und-rewrites/
January 26th, 2011 - 21:21
This is exactly what I was looking for, thanks a trillion!
September 20th, 2011 - 18:50
I don’t understand how you are using version 1.5. Aren’t we up to version 1.4.29 of Lighty? (As of July 2011)
October 5th, 2011 - 13:21
You’re talking three years ago at this point, I was running a pre-release and it ran well for a long time. I’m back to running Apache again at this point, this is the version I was running http://blog.lighttpd.net/articles/2007/09/06/pre-release-lighttpd-1-5-0-r1992