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
Responses to “Wordpress Permalinks with Lighttpd”
May 18th, 2008 at 7:57 pm
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.
May 19th, 2008 at 11:54 am
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
May 19th, 2008 at 2:50 pm
@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.
June 23rd, 2008 at 8:11 am
I just migrated from apache to lighttpd and thanks to your help my wordpress site works like a charm, AFAIKT
July 2nd, 2008 at 1:59 am
Hi,
For me the lua just nagged about ‘unexpected symbol’. Which is fixed when you change all of the “-characters to ‘-characters.
September 6th, 2008 at 5:07 am
What do I have to do when Wordpress is in a subdirectory like ‘www.example.com/blog/’?
September 11th, 2008 at 9:06 am
@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
September 20th, 2008 at 10:24 pm
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!
October 13th, 2008 at 7:31 pm
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!
October 16th, 2008 at 4:45 pm
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
October 17th, 2008 at 1:57 am
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
December 17th, 2008 at 1:40 pm
nice blog!! I really liked this blog.your post are good trip for me Thanks for sharing (:
January 6th, 2009 at 4:10 pm
@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)
January 16th, 2009 at 1:32 am
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
January 30th, 2009 at 6:53 pm
I used the mod_rewrite way and it make a mess on the index files when using subdirectories.
February 13th, 2009 at 6:13 am
hi how to convert this code (RewriteRule ^(css|js) - [L]) to lighttpd mod rewrite
May 18th, 2008 at 2:37 pm
I love you. Er.. I mean, thanks for the script.