How to get request parameter in lua or nginx?

I am trying to implement this - https://gist.github.com/MendelGusmao/2356310 Lua, an abbreviated nginx based URL. The only change I want to implement is when some query string parameter comes with an abbreviated URL. I need to accept this parameter and paste into a long url.

eg. http://google.com?test=2 will look like http://abc.in/abc by clicking on http://abc.in/abc?test=3 I'm redirecting to http://google.com?test = 3 .

To do this, I need to take the query string parameters from $ request_URI, can anyone help with some code?

+6
source share
2 answers

You should be able to use ngx.var.arg_name , where name is the name of the query parameter that you want to access. For more information about processing query parameters, see Variables with Infinite Names . you can also check out my blog post for Lua nginx / openresty examples.

Alternatively, you can use ngx.req.get_uri_args() to retrieve all query parameters in a single table. See this section in the same tutorial for a brief comparison of these methods.

+14
source

You can also use ngx.var.QUERY_STRING to access the query string and unescape and parsing.

+5
source

Source: https://habr.com/ru/post/976089/


All Articles