需求:获取到请求参数里的url后,重定向到此url
思路:在请求的rewrite_by_lua阶段进行需求重定向
废话不多说,直接上代码,一目了然
location /to {
default_type ‘text/plain‘;
rewrite_by_lua_block {
local function urlDecode(s)
s = string.gsub(s, ‘%%(%x%x)‘, function(h)
return string.char(tonumber(h, 16)) end)
return s
end
local url = ngx.var.arg_redirect
local ret = urlDecode(url)
ngx.redirect(ret, ngx.HTTP_MOVED_PERMANENTLY)
}
}