LongSpine.com Yes, we are lazy.

14Sep/090

Wordpress Pretty Permalinks on Lighttpd

At some point in your Wordpress-life, you need a pretty permalink (name of the link at the navigation bar). On Apache we can easily use the rewrite module (mod_rewrite) which works pretty well. On the other hand, I found it confusing to make the equivalent rewrite rule on Lighttpd, therefore I use the other module called magnet module (mod_magnet) instead. And these are some simple steps how to use it:

Install Magnet Module

Simply install it from the default repositories.

sudo aptitude install lighttpd-mod-magnet

Dont forget to enable the module:

sudo lighty-enable-mod magnet

Lighttpd Configuration

Edit the configuration file:

sudo vi /etc/lighttpd/lighttpd.conf

If you do not use vhosts, add the following to the end of the file:

magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )

If you do use vhosts, add that line to your vhost instead:

$HTTP["host"] =~ "(^|\.)example\.com" {
    server.document-root = "/var/www/example.com"
    magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )
}

Where example.com is the name of your website and /var/www/example.com is the directory where your website is.

Make a Lua script, assuming that Lua is supported by default (I didn't have to install anything at that time):

sudo vi /var/www/example.com/rewrite.lua

Again, don't forget change /var/www/example.com to your own setting.

Add the following Lua script into the file, thanks to Sudhaker.

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

Reload the module:

sudo /etc/init.d/lighttpd force-reload

Now visit your Wordpress's permalinks configuration, http://example.com/wp-admin/options-permalink.php and use the default or follow this guide. Enjoy!

   

Recommended Reading

Recent Comments

Archives

Meta