I've setup a static website on GCP using this tutorial. So I have a bucket and a load balancer.

I'm trying to setup URL redirections in the load balancer to avoid BC breaks on old URLs. I want an user arriving to https://example.org/foo to be redirected to https://example.org/bar. I have a dozen redirections like this to setup.

Is there a way to configure that in the load balancer? Or anywhere else?

I've searched in the routing rules, but I'm expecting a "from" field where I could enter "/foo" and a "destination" field where I could enter "/bar", but I got this:

enter image description here

Or should I use the YAML Path matcher? But I can't find any example of this basic case.

1 Answer 1


There is a possibility of URL redirection in GCP Load balancer and from the information provided by you it is observed that a bucket and a Global HTTPs Load balancer were created in your environment.

To proceed with the URL redirection, you can add configuration to a URL map so that the map routes traffic to the appropriate service.

Replace the host and path as per the requirement in the below configuration related to url redirection.

  hostRedirect: "new-host-name.com" # Omit to keep the requested host
  pathRedirect: "/new-path" # Omit to keep the requested path; mutually exclusive to prefixRedirect
  prefixRedirect: "/newPrefix" # Omit to keep the requested path; mutually exclusive to pathRedirect
  redirectResponseCode: FOUND
  stripQuery: True

For more information please refer to the official documentation.

  • Thank you. I had tried this way, but I couldn't figure out what I was supposed to put in "defaultService". Thanks to your answer, I've retried, and using "global/backendBuckets/<the name of my backend bucket>" was the thing I am supposed to do. Thank you!
    – Gregoire
    Mar 26 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.