How to get a part of url?
For example:
have url: /aaa/bbb/ccc?test=123
I need to get part of url /ccc into the nginx variable.
I want to get a variable with a value = "ccc"
I will use the variable in location {}
How to get a part of url?
For example:
have url: /aaa/bbb/ccc?test=123
I need to get part of url /ccc into the nginx variable.
I want to get a variable with a value = "ccc"
I will use the variable in location {}
2
Answers
Commands can be stacked, to make it smaller. Harder
to explain the logic that way, but it’s the same thing.
I would suggest to use a library, available from official OpenResty Package Manager
OPM
:This library works for both
GET
andPOST
variables:The API is a little bit weird because the function returns 3 values.
In case of failure, it will return
false, ErrorMessage, false
.In case of success, it will return
GetTable, PostTable, FilesTable
. Except this, it just works.You can use it in a location block: