example
- nginx configuration
# 重写 uri,将 /abcxxx 重写为 /abc-xchenhao-xxx
rewrite /abc(.*) /abc-xchenhao-$1 last;
location /abc {
# 输出 ngx.var.uri 和 ngx.var.request_uri 的值
content_by_lua_block {
ngx.print('ngx.var.uri: ' .. ngx.var.uri .. "\nngx.var.request_uri: " .. ngx.var.request_uri)
}
}
- result
$ curl https://example.com/abcdef?foo=bar
ngx.var.uri: /abc-xchenhao-def
ngx.var.request_uri: /abcdef?foo=bar
the difference
ngx.var.request_uri
The original request URI sent by the client, including parameters, cannot be modified, for example /abcdef?foo=bar
ngx.var.uri
The URI of the current request, which can contain parameters and can be internally redirected or modified, for example /abc-xchenhao-def
reference
- http://t.zoukankan.com/chenpython123-p-10832393.html
- https://www.jianshu.com/p/384556e3938b