To achieve this, you need to utilize the URL rewrites of the load balancer. This will allow you to change host, path, or both of them before directing traffic to your backend services.
Assuming everything is already set up, you just need to edit the routing rules of your load balancer.
Edit the load balancer and select Routing Rules.
In the mode section, select “Advanced host and path rules”.
On the YAML file, create a “rouetRules” with “matchRules” for your URL request that will distinguish your backend service.
Indicate your desired path by creating “urlRewrite” with “pathPrefixRewrite”.
Sample YAML code below:
name: matcher
routeRules:
- description: service
matchRules:
- prefixMatch: /bar # Request path that need to be rewrite.
priority: 1
service: projects/example-project/global/backendServices/<your-backend>
routeAction:
urlRewrite:
pathPrefixRewrite: /foo/bar # This will be your desired path.
For a more comprehensive guide, you can follow this article.