I found few url-rewrite based solution for enabling Permalinks in Wordpress+Lighttpd but none of them worked flawlessly. Guys, all we need here is something similar to following Apache rewrite code (without any side effect, like 404 header etc).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

So I continued searching for the perfect solution, and here is what I found. It works like charm on Wordpress 2.5 :-) Another victory for KISS! (keep it sweet and simple)

Content of /etc/lighttpd/lighttpd.conf

$HTTP["host"] == "dev.sudhaker.com" {
  server.document-root = "/sites/sudhaker.com/htdocs"
  magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )
}

Note: please make sure that mod_magnet is enabled :-)

And content of $WP_ROOT/rewrite.lua

attr = lighty.stat(lighty.env["physical.path"])
 
if (not attr) then
  lighty.env["uri.path"] = "/index.php"
  lighty.env["physical.rel-path"] = lighty.env["uri.path"]
  lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end

A similar workaround for Drupal is suggested in this category :-)

Note: It only works on lighttpd 1.4.2 (and latter) ;-)

Cheers,
Sudhaker

Posted Friday, April 11th, 2008 at 10:11 am
Filed Under Category: Wordpress
You can skip to the end and leave a response. Pinging is currently not allowed.

18

Responses to “Wordpress Permalinks with Lighttpd”

Jacob

I love you. Er.. I mean, thanks for the script.

skycrew

hi, my lighttpd version is 1.4.18

but this script not working for me

when I paste this script in my lighttpd.conf

$HTTP["host"] =~ "dev\.skycrewz\.net$" {
  server.document-root = "/shared/sites/htdocs_drupal5"
  magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )
}

my blog cannot load. can you help me? I have 2 blog. One is install in directory and another one in subdomain.

Denbert

I’m having WP 2.5.1 and Lighttpd on debian etch, and I’m having some questions to this interesting post:

Where do I put this code:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I enabled mod_magnet, but a restart of lighttpd gave me this:

Starting web server: lighttpd2008-05-19 19:49:14: (plugin.c.165) dlopen() failed for: /usr/lib/lighttpd/mod_magnet.so /usr/lib/lighttpd/mod_magnet.so: cannot open shared object file: No such file or directory
2008-05-19 19:49:14: (server.c.594) loading plugins finally failed

I’m obviously missing the main part here :-(

Please guide me in the right direction.

/ Denbert

Sudhaker

@skycrew

Did you enable mod_magnet?

Folder /shared/sites/htdocs_drupal5 should be replaced by your real wordpress root. Since I don’t know your setup, unable to suggest anything. Try to get it working without permlink first then try to make permlink working.

@Denbert

Lighttpd does not know anything about .htaccess or apache specific directives. Please do a step-by-step debugging through following baby steps.

1. Get site working with Lighttpd
2. Simply enable mod_magnet (and test it)
3. Then add magnet.attract-physical-path-to directive (and test it)
4. Try enabling permlink (and test it)

I can’t help if enough information is not provided. Hope this help.

Evert Meulie

I just migrated from apache to lighttpd and thanks to your help my wordpress site works like a charm, AFAIKT :-)

Jani

Hi,

For me the lua just nagged about ‘unexpected symbol’. Which is fixed when you change all of the “-characters to ‘-characters.

wil

What do I have to do when Wordpress is in a subdirectory like ‘www.example.com/blog/’?

Walter Cruz

A example in a subdirectory will be useful to me too.

Sudhaker

@Jani - that was because of “wptexturize screw up” ; for some reason WP converts all opening double quote to “ & closing double quote to ” :-( Anyway, this is fixed now in my WP setup, and I confirmed that double quote works well in lua

@wil - simplest would be to keep everything same except following line

lighty.env["uri.path"] = "/blog/index.php"

or better would be something like this (not tested so please don’t kill me if this doesn’t work)

Content of /etc/lighttpd/lighttpd.conf

$HTTP["host"] == "dev.sudhaker.com" {
  server.document-root = "/sites/sudhaker.com/htdocs"
  $HTTP["url"] =~ "^/blog/" {
    magnet.attract-physical-path-to = ( server.document-root + "/blog/rewrite.lua" )
  }
 
}

And content of $WP_ROOT/rewrite.lua

attr = lighty.stat(lighty.env["physical.path"])
 
if (not attr) then
  lighty.env["uri.path"] = "/blog/index.php"
  lighty.env["physical.rel-path"] = lighty.env["uri.path"]
  lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
Praveen Kumar

The solution that you have posted for the subdirectory works fine, dude. I have tried it and using it on my Wordpress installation. It really helped me with my migration from Apache to Lighttpd. Thanks a ton!

Robert

I just set this up and it is the only 100% perfectly working setup that I have seen. Alot of mod_rewrite setups get close but interfere with other folders not related to wordpress. This one allows my phpmyadmin install to co-exist and does proper rewrites. Thanks!

Guy

Hi Sudhaker,

While your solution results in correct behavior, its use of mod_magent may result in performance hit and, i believe is an overkill.

See my reply to your comment in my post
http://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/

Regards,
Guy

Sudhaker

I did a performance comparison between mod_magnet and mad_rewrite based solution. Results are posted at following URL

http://sudhaker.com/web-development/lighttpd-modules-compared-mod_magnet-and-mod_rewrite.html

According to my basic testing results, mod_rewrite is slightly better performing than mod_magnet.

FYI: I’ll continue using rewrite.lua because performance hit is not significant and it provides more reliable and consistent solution.

Cheers,
Sudhaker

tony

nice blog!! I really liked this blog.your post are good trip for me Thanks for sharing (:

Ark74

@Denbert
You needed to install the lighttpd-mod-magnet package in order to enable mod_magnet.

@Sudhacker
I used the mod_rewrite way and it make a mess on the index files when using subdirectories.
I’ve been trying to use the mod_magnet you wrote on a site.org/user/blog, but i only get 404 error :-/

Here is how i have done it: http://switnet.dyndns.org/ark/pmwiki/pmwiki.php/Varios/Wordpress-URL

(if you would like to edit, just let me know)

Hamilton

This is great! Thank you for solving a problem I’ve been annoyed with for so long. I was compiling the lighttpd 1.4.20 upgrade anyways, so I tossed in lua support and set up your mod_magnet solution. Works perfectly! <3

konya web tasarım

I used the mod_rewrite way and it make a mess on the index files when using subdirectories.

thirumalai

hi how to convert this code (RewriteRule ^(css|js) - [L]) to lighttpd mod rewrite

Leave a Reply

CAPTCHA image