• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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 http://yoursite.com/community/ 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.
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. xboxforum.pl/showthread.php?t=145920 ==> xboxforum.pl/threads/sprzet-do-rgh-co-bedzie-potrzebne.95706/ (works fine, links are connected correct)
2. xboxforum.pl/jtag-rgh-194/sprzet-do-rgh-co-bedzie-potrzebne-145920/ (google link) ==> don't works, correct link is xboxforum.pl/threads/sprzet-do-rgh-co-bedzie-potrzebne.95706/

any sugestions?