Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get query parameter in lua or nginx?

I am trying to implement this- https://gist.github.com/MendelGusmao/2356310 Lua,nginx based URL shortener,The only change i want to implement is when some query string parameter comes with shortened URL i need to take that parameter and insert into the long URL.

e.g. http://google.com?test=2 will be like http://abc.in/abc while hitting on http://abc.in/abc?test=3 I get redirected to - http://google.com?test=3.

For that i need to take query string parameters from $request_URI, can any one help with some code?

like image 958
mannuscript Avatar asked Oct 01 '14 03:10

mannuscript


People also ask

How do I give a parameter query?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

Can a get request have query parameters?

For GET requests, input can be specified only as query parameters, because a GET request cannot have a body. This example shows a GET request on the search resource, with two query parameters in the query string.

What is Lua Nginx module?

Nginx+Lua is a self-contained web server embedding the scripting language Lua. Powerful applications can be written directly inside Nginx without using cgi, fastcgi, or uwsgi.

What is query parameter in REST API?

You can use query parameters to control what data is returned in endpoint responses. The sections below describe query parameters that you can use to control the set of items and properties in responses, and the order of the items returned.


1 Answers

You should be able to use ngx.var.arg_name where name is the name of the query parameter you want to access. See Variables with Infinite Names section in this tutorial for details on query parameter handling; you may also check my blog post for Lua nginx/openresty examples.

As an alternative, you can use ngx.req.get_uri_args() to retrieve all query parameters as one table. See this section in the same tutorial for the brief comparison between these methods.

like image 50
Paul Kulchenko Avatar answered Sep 21 '22 13:09

Paul Kulchenko