Lighttpd - URL rewrite with mod_magnet


Well-known member
I have seen a few suggestions to rewrite xF Urls using url.rewrite directives. Although it may work in most cases, it is not the recommended Lighttpd way.

One big advantage of Lighttpd is support of the Lua scripting language through the mod_magnet module. As Lighttpd doesn't provide Apache's is_file/is_dir check out of the box, this module comes into play. Lets assume xF is already installed under you now add the magnet part to it.


mod_magnet needs a Lighttpd which is compiled with the LUA-support option ( --with-lua). Lua 5.1 or higher are required by the module. In your Lighttpd config file, add the mod_magnet module along with your other server modules:

server.modules = ( ..., "mod_magnet", ... )


In the Lighttpd config file for your xF installation:

$HTTP["url"] =~ "^/community" {
    # we only need index.php here.
    index-file.names = ( "index.php" )
    # for clean urls
    magnet.attract-physical-path-to = ( "/etc/lighttpd/xenforo.lua" )

The xenforo.lua file:

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["request.orig-uri"]  = lighty.env["request.uri"]
  lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
This Lua snippet routes all Url requests to non-existing locations to xF.
  • Like
Reactions: DRE


Active member
Excellent, clear post. Thanks for taking the trouble to post this for us sometimes unloved Lighttpd users!


I'm used your config and links in xenforo works fine. But in google I have old links form vbseo and don't redirect:
1. ==> (works fine, links are connected correct)
2. (google link) ==> don't works, correct link is

any sugestions?