Nginx request_uri不带参数 [英] Nginx request_uri without args
问题描述
如何获取request_uri
的值而末尾没有附加args.我知道有一个uri
变量,但我需要Nginx文档指出的原始值:
How do I get the value of request_uri
without the args appended on the end. I know there is a uri
variable but I need the original value as the Nginx documentation states:
request_uri
此变量等于原始请求URI,该请求URI是从 客户端,包括args.无法修改.看看$ uri 重写后/更改后的URI.不包含主机名.例子: "/foo/bar.php?arg=baz"
This variable is equal to the original request URI as received from the client including the args. It cannot be modified. Look at $uri for the post-rewrite/altered URI. Does not include host name. Example: "/foo/bar.php?arg=baz"
推荐答案
您正在寻找$ uri.它没有$ args.实际上,$ request_uri几乎等于$ uri $ args.
You're looking for $uri. It does not have $args. In fact, $request_uri is almost equivalent to $uri$args.
如果您确实希望完全删除$ args的$ request_uri,则可以执行此操作.
If you really want exactly $request_uri with the args stripped, you can do this.
local uri = string.gsub(ngx.var.request_uri, "?.*", "")
您将需要提供lua,但这将完全满足您的要求.
You will need to have lua available but that will do exactly what you're asking.
这篇关于Nginx request_uri不带参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!