GCP 负载均衡器重定向,同时保留查询参数
在我的 GCP 项目中,我在我的一个负载均衡器上执行主机和路径规则重定向。我试图让重定向来传递查询参数,但事实并非如此。
本质上是想这样做:
subdomain.domain.com?foo=bar -> www.domain.com/path?foo=bar。
重定向适用于路径,但不保留查询参数。从我在这里看到的,它应该有效。
https://cloud.google.com/load-balancing/ docs/https/traffic-management#redirects
重定向到通过修改主机、路径或 URL 的主机和路径部分形成的不同 URL,并删除或保留任何查询参数< /强>。
In my GCP project am a doing a Host and path rules redirect on one of my load balancers. I am trying to get the redirect to pass the query parameters, but it is not.
Essentially trying to do:
subdomain.domain.com?foo=bar -> www.domain.com/path?foo=bar.
The redirect works to the path, but it does not keep the query params. From what I can see here, it should work.
https://cloud.google.com/load-balancing/docs/https/traffic-management#redirects
Redirect to a different URL formed by modifying the host, path, or both the host and path portion of the URL, and either stripping out or retaining any query parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Google Cloud 中,stripQuery 字段还可以与负载均衡器一起使用,特别是 GCP HTTP(S) 负载均衡器。此功能允许您配置在将请求转发到后端服务时是否包含或删除传入请求 URL 中存在的查询字符串。
ie:如果向“example.com/path?key=value”发出请求,并且 stripQuery 设置为 false,则该请求将被转发到后端服务,就像向“发出”一样example.com/path?key=value”。
通过禁用 Google Cloud 负载均衡器中的 stripQuery 功能,我们可以将查询参数转发到我们重定向到的新主机。
这是一个配置 YAML,我们可以使用该配置将站点重定向到另一个保留查询参数的站点。
如果您在高级主机和路径规则中使用 DefaultRedirect:
您应该在 Google Cloud Load Balancer 编辑页面中取消选中剥离查询高级路由规则路由规则。
参考:
在此处输入图片说明
In Google Cloud, the stripQuery field can also be used with a Load Balancer, specifically the GCP HTTP(S) Load Balancer. This feature allows you to configure whether the query string present in the incoming request's URL will be included or removed when the request is forwarded to a backend service.
i.e: if a request is made to "example.com/path?key=value", and stripQuery is set to false, the request will be forwarded to the backend service as if it were made to "example.com/path?key=value".
By disabling the stripQuery feature in Google Cloud Load balancer we can forward the query params to the new host we have redirected to.
Here is a configuration YAML we can use to redirect the site to another site preserving the query parameters.
If you are using DefaultRedirect in Advanced host and path rule:
You should uncheck the Strip query in Google Cloud Load Balancer Edit Page for Advanced Route Rules Routing Rules .
Reference:
enter image description here