Emil Haukeland Mostly for myself, but maybe something useful for you too?

17Apr/10

URL rewriting for wordpress and lighttpd

Pronounced: lighty

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%/

Comments (11) Trackbacks (4)
  1. thanks, you rock! simple, to-the-point, concise = WIN

  2. Thanks! Seems to be working so far.

  3. Thank you. The configuration works flawlessly for my lightty.

  4. 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!

  5. 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.

  6. 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/

  7. 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.

  8. 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 :) ~

  9. Thanks for this ! Works perfectly

  10. Very nice, I think this is the best solution for WordPress rewrite rules in Lighttpd.

  11. Thank you kind sir, this helped me get things back on track.


Leave a comment

(required)