Emil Haukeland

URL rewriting for wordpress and lighttpd

by Emil Haukeland on Feb.11, 2007, under lighttpd, php, web, wordpress

URL rewriting in lighttpd works somewhat a bit different than in apache web server. Wordpress will not generate those nice URL’s by default and need some help. I googled around for a solution and found a lot of attempts to solve this. It seems like everyone’s trying to make this as difficult as possible. I have tried to make this a bit more simple.

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, .html, .gif, .png, .jpg and .txt files at root from rewriting
    "^/(.*.(php|html|gif|png|jpg|txt)$)" => "$0",
    # EDIT: Added a $ at the end of the regexp and
    # excluding of a few more filenames to
    # solve the problem reported by teko. Thanks!
 
    # Handle permalinks and feeds
    "^/(.*)$" => "/index.php/$1"
  )
}

These three rules should cover for every plugin and functionality. If you have other folders witch 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:
/%year%/%monthnum%/%day%/%postname%/

I hope this was helpful :-)


14 Comments for this entry

6 Trackbacks / Pingbacks for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...