Nginx request_uri without args

2019-02-08 05:09发布

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

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"

标签: regex nginx
2条回答
做自己的国王
2楼-- · 2019-02-08 06:04

You're looking for $uri. It does not have $args. In fact, $request_uri is almost equivalent to $uri$args.

If you really want exactly $request_uri with the args stripped, you can do this.

local uri = string.gsub(ngx.var.request_uri, "?.*", "")

You will need to have lua available but that will do exactly what you're asking.

查看更多
该账号已被封号
3楼-- · 2019-02-08 06:09

I use this map, which works without lua:

map $request_uri $request_uri_path {
  "~^(?P<path>[^?]*)(\?.*)?$"  $path;
}
查看更多
登录 后发表回答