'Is it possible to rewrite an incoming request to the backend service (e.g. Cloud Run) from a GCP load balancer?
I have two services running Cloud Run such as api1 and api2.
I set up a global external HTTP(S) load balancer (classic) in GCP to route the path to both services.
such as
| Paths | Action | Backend |
|---|---|---|
| /api1/* | Route traffic to a single backend | service-api1 |
| /api2/* | Route traffic to a single backend | service-api2 |
When I send a request mydomain/api1/aaa/ccc/, api1 get the request url as mydomain/api1/aaa/ccc/
When I send a request mydomain/api2/ddd/eee/, api2 get the request url as mydomain/api2/ddd/eee/
Is there a way to rewrite the incoming request for api1, so that api1 will see the request as mydomain/aaa/ccc/?
This also apply to api2, so api2 will see the request as mydomain/ddd/eee/
From the Rewrite documentation,
The load balancer provides the following mutually exclusive primary actions:
- Reads the incoming URL in the request.
- Replaces the host, the path, or both the host and the path, transforming the URL before directing traffic to the backend service or backend bucket.
I think there is a way, but I don't manage to make it work.
Any advice?
Solution 1:[1]
In load balancing console page
- Select
Advanced host and path rule (URL redirect, URL rewrite)inHost and path rules
- Add a path rule and edit path rule as below (show Add-On action)
- Save and update the changes.
When you send a request mydomain/api1/aaa/ccc/, api1 will see the request as mydomain/aaa/ccc/.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


