Score:0

How to setup 301 redirections in GCP load balancer?

lk flag

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.

Score:1
nu flag

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.

urlRedirect:
  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.

Gregoire avatar
lk flag
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!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.