Some Example Lua Code

Lua is a perfect scripting language for quick and lightweight logic - for proxies, middleware applications, and application level routing.

I wrote this small lua script as a test for redirecting one domain host to another:

json = require("json")

testString = [[ { "example.com": "example.org" } ]]
o = json.decode(testString)
table.foreach(o,print)

myhost = lighty.request["Host"]

if (o[myhost]) then
    lighty.header["Location"] = "http://www." .. o[myhost]
    return 301
end
By Albert on February 10, 2011 8:52 PM

Categories: