![](/img/trans.png)
[英]How do I get the query string of a URL (the parts after the question mark)?
[英]How do I write an Nginx location to capture everything after a question mark in a query string?
我有一个看起来像这样的URL:
http://somedomain.loc/api/things/index?take=10&skip=0&page=1&pageSize=10&sort%5B0%5D%5Bfield%5D=date_created&sort%5B0%5D%5Bdir%5D=desc
我需要一个与/api/things/index
匹配的Nginx位置,并在?
之后捕获查询字符串中的所有内容?
。 我已经试过了:
location ~ /api/things/index?(.*) {
return 200 $1;
}
但是$1
是空的。 如果我更改此设置以捕获整个内容,例如:
location ~ (/api/things/index?.*)
我得到了/api/things/index
,但是问号之后什么也没有。 我已经在多个在线正则表达式测试仪中尝试过正则表达式,并且捕获似乎可以正常工作,但是关于Nginx的位置肯定有些我不了解的地方。 请帮忙!
你可以试试看
location ~/api/things/index/(.*)$ {
return 200 $1;
}
从OP编辑
如下面的评论所示,事实证明我的问题不是正则表达式,而是使用捕获而不是$args
。 解决方案是:
location ~/api/things/index(.*)$ {
return 200 $args;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.