I want to write a script that rewrite a URL in mod_lua, that is I want to inherit the query string like QSA flag of mod_rewrite.
mod_rewrite config:
RewruteCond ^/foobar/([0-9A-Za-z]+)/(.+)$
RewriteRule ^.*$ /foobar/$2?_ID_=$1 [QSA,L]
I try to code in mod_lua as below, but it does not work well. Please tell me what is wrong? And, Does it will be able to be more simple code?
mod_lua config:
LoadModule lua_module modules/mod_lua.so
LuaHookTranslateName /usr/local/httpd/conf/extra/lua/router.lua app_routing
/usr/local/httpd/conf/extra/lua/router.lua routing:
require "apache2"
function app_routing(r)
local matches = r:regex(r.uri, [[^/foobar/([0-9A-Za-z]+)/(.+)$]])
if matches then
r.uri = "/foobar/" .. matches[2]
if r.args then
r.args = r.args .. "&_ID_=" .. matches[1]
else
r.args = "?_ID_=" .. matches[1]
end
end
end