GCP 负载均衡器重定向,同时保留查询参数

发布于 2025-01-10 21:08:58 字数 567 浏览 4 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意 2025-01-17 21:08:58

在 Google Cloud 中,stripQuery 字段还可以与负载均衡器一起使用,特别是 GCP HTTP(S) 负载均衡器。此功能允许您配置在将请求转发到后端服务时是否包含或删除传入请求 URL 中存在的查询字符串

当 stripQuery 设置为 false 时,查询字符串将包含在
将流量转发到后端服务时的路径。

ie:如果向“example.com/path?key=value”发出请求,并且 stripQuery 设置为 false,则该请求将被转发到后端服务,就像向“发出”一样example.com/path?key=value”。


通过禁用 Google Cloud 负载均衡器中的 stripQuery 功能,我们可以将查询参数转发到我们重定向到的新主机。


这是一个配置 YAML,我们可以使用该配置将站点重定向到另一个保留查询参数的站点。

defaultService: projects/example/global/backendServices/example-test
name: example-matcher1
routeRules:
- urlRedirect:
    stripQuery: false
    hostRedirect: ie.example.com
    redirectResponseCode: MOVED_PERMANENTLY_DEFAULT

如果您在高级主机和路径规则中使用 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.

When stripQuery is set to false, the query string will be included in
the path when forwarding traffic to the 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.

defaultService: projects/example/global/backendServices/example-test
name: example-matcher1
routeRules:
- urlRedirect:
    stripQuery: false
    hostRedirect: ie.example.com
    redirectResponseCode: MOVED_PERMANENTLY_DEFAULT

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文