WordPress on Lighttpd: Rewrite Rules With WP Super Cache and WPtouch

As a few of my readers already know, this weblog is run by a WordPress 2.x installation on a lighttpd web server (on top of a Debian Linux host). I have also installed, among others, the following plugins for WordPress:

  • WP Super Cache — Serves a cached HTML version of WordPress pages instead of serving each page as PHP output for every single request. This speeds up loading time and reduces the web server load. A lot!
  • WPtouch — When a user is using a mobile device, e.g., an iPhone, iPod touch, Android phone etc., they will see a slightly different layout of this blog, particularly optimized for small screen sizes.

<img class=“alignright size-medium title=“Screenshot WPTouch” src="/images//2009/11/Screen-shot-2011-05-15-at-14.35.39-164x300.png” alt="" width=“164” height=“300” srcset="/images/2009/11/Screen-shot-2011-05-15-at-14.35.39-164x300.png 164w, /images/2009/11/Screen-shot-2011-05-15-at-14.35.39.png 414w" sizes="(max-width: 164px) 100vw, 164px" />lighttpd does not understand Apache’s RewriteRules that are used for permalinks in WordPress. Therefore, you’ll have to come up with your own set of rewrite rules. Based on the rewrite.lua script initially written by Giovanni Intini, I have come up with a slightly modified version that takes the presence of the WPtouch plugin into account.

To install this script, perform the following steps:

  1. Download the latest version of the rewrite.lua script from my github project site.
  2. Place rewrite.lua in the root directory of your WordPress installation, i.e., the same directory where you find the WordPress PHP files such as wp-config.php.
  3. Update your lighttpd config file for the host running WordPress and include this command:
`magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )`<sup><a href="#footnote_0_1246" id="identifier_0_1246" class="footnote-link footnote-identifier-link" title="This requires ModMagnet being set up for your lighttpd server. Follow the previous link if you need help installing it.">1</a></sup>
  1. Make sure the Mobile device support option of the WP Super Cache plugin is enabled and the Rejected User Agents list is up-to-date. You’ll find those options in the Settings -> WP Super Cache menu of WordPress once WP Super Cache has been activated.

The lighttpd host configuration should now look somewhat similar to this:

$HTTP["host"] == "myblog.com" {<br /> server.document-root = "/srv/www/myblog/wordpress"<br /> accesslog.filename = "/var/log/lighttpd/``myblog``/access.log"<br /> magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )<br /> }

Restart lighttpd to put the changes in place. Check your error log for any strange entries. Check the WP Super Cache settings of your blog and try to view it from a mobile device or an iPhone simulator, e.g., iPhoney.

Let me know if you’d like to further improve the rewrite.lua code. Just go ahead, clone it from the github repository and start working on it! If you’re interested in writing your own LUA code check out the Programming in Lua book or the Programming in LUA website.


comments powered by Disqus