[英]Redirect ALL get parameters to another domain in Nginx
Only answers I can find for this have specific parameters and don't work if the parameters change. 我为此只能找到的答案具有特定的参数,并且如果参数更改则无法使用。
I have a URL coming in such as: 我有一个网址,例如:
/logs.php?user_id=10032&account_id=10099&message=0&interval=1&online=1&rsid=65374826&action=update&ids=827,9210,82930&session_id=1211546313-1602275138
I need to redirect this url to a completely different domain and file but keep the get params. 我需要将此URL重定向到一个完全不同的域和文件,但保留get参数。
So it ends up redirecting to: 因此,最终重定向到:
https://example.com/the_logger.php?REPEAT_ALL_GET_PARAMETERS_HERE
Here is what I have unsuccessfully tried so far: 到目前为止,这是我尝试失败的内容:
location logs.php
{
rewrite https://example.com/the_logger.php?$args last;
}
But it doesn't seem to match the url or redirect. 但这似乎与url或重定向不匹配。 I think I'm misunderstanding the logic of nginx confs.
我认为我误解了Nginx conf的逻辑。 If it were .htaccess I think I'd be okay.
如果是.htaccess,我想我会好的。 I can put a few more examples here if need be of what I'm trying to achieve.
如果需要,我可以在此处提供更多示例。
As you state this is a redirect and not reverse proxying a request, I would use the return
directive to tell the client to do a 301
or 302
. 当您声明这是重定向而不是反向代理请求时,我将使用
return
指令告诉客户端执行301
或302
。 Using the return directive is the simpler and more recommend approach to redirecting a client. 使用return指令是重定向客户端的更简单, 更推荐的方法 。
Something like should do what you want: 诸如此类的事情应该可以满足您的要求:
location /logs {
return 302 https://example.com/the_logger.php$is_args$args;
}
Where $is_args
would output a ?
$is_args
将在哪里输出?
if and only if the query string is not empty, and $args
is the query string itself 当且仅当查询字符串不为空,并且
$args
是查询字符串本身时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.