17Apr/10
URL rewriting for wordpress and lighttpd

Please note: Since I managed to lose my original database-file for this blog I have tried to recreate this post since quite a few of you found it useful.
In your lighttpd.conf or 10-rewrite.conf enable mod_rewrite and then paste the following code (you will need to edit the $HTTP["host"] though):
$HTTP["host"] =~ "emil.haukeland.name" { url.rewrite-final = ( # Exclude some directories from rewriting "^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0", # Exclude .php files at root from rewriting "^/(.*.php)" => "$0", # Handle permalinks and feeds "^/(.*)$" => "/index.php/$1" ) }
These three rules should cover for every plugin and functionality. If you have other folders which you will need to access without any redirection (images in a separate folder etc), you have to add this to the first rule.
Now change the setting in Options->Permalinks to Custom and create your permalink structure. Personally I prefer this:
http://emil.haukeland.name/%category%/%year%/%postname%/
July 23rd, 2010 - 07:20
thanks, you rock! simple, to-the-point, concise = WIN
July 25th, 2010 - 01:05
Thanks! Seems to be working so far.
July 28th, 2010 - 10:25
Thank you. The configuration works flawlessly for my lightty.
November 10th, 2010 - 04:20
Thanks! Just switched from Apache to LigHTTPD and ran in to trouble with fancy perma-links. You were one of the first results on a Google search for it, and your advice worked perfectly!
November 30th, 2010 - 22:04
Permalinks works fine. Only thing is, this code introduces a logout bug. Try hitting Logout. You land at a brand new login field, right? Anyways, now click the ‘Return to ‘ in the upper left corner (or just enter http://bloghost), and you’ll see in the meta admin control frame that you are still logged in. All /wp-admin/ controls are accessible. In short, something in your code seems to prevent the auth cookie from being dropped. I’m no expert so, leaving this to someone else. Ty for a fine effort anyways.
November 30th, 2010 - 22:34
These lines seem to do the trick:
url.rewrite = (
“^/(.*)\.(.+)$” => “$0″,
“^/(.+)/?$” => “/index.php/$1″
)
Of course they should go in lighttpd.conf
Source:
http://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/
March 11th, 2011 - 18:00
One question:
This line:
# Exclude some directories from rewriting
“^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)” => “$0″,
…means that accessing, say, wp-admin without a trailing slash doesn’t work.
(http://yourdomain.com/wp-admin)
I just took off the trailing slash in the regex — any thoughts on whether there are any adverse consequences for this? I can’t think of any.
March 11th, 2011 - 18:55
I believe you’re right. What it should mean is that the slash will be included in the param that’s sent to wordpress. I’ll test this and update the original article to reflect this change.
Thank you
~
May 25th, 2011 - 11:10
Thanks for this ! Works perfectly
October 29th, 2011 - 11:18
Very nice, I think this is the best solution for WordPress rewrite rules in Lighttpd.
November 24th, 2011 - 23:48
Thank you kind sir, this helped me get things back on track.