Custom 301 redirects for static site using GCP Storage

I am considering whether to host my static website on an AWS S3 bucket or using Google Cloud Platform Storage, and, as I already use GCP and with it being generally cheaper, I would really like to utilize that option.

My issue is that I often need to create custom 301 redirects for my site, like:

https://example.com/page -> https://anotherexample.com/another-page

S3 seems to handle this well, but I'm not finding any documentation on custom redirects from GCP.

Is this possible with GCP Storage buckets yet?


Short answer: GCP does not seem to support such a feature.

However there is a hard way to do this in GCP:

You can setup an instance group of micro virtual machines with Nginx, configured to make redirects for you.

Then you'll need to setup a load balancer to handle all requests. It supports forwarding rules, so you may configure it to send https://example.com/page requests to nginx VM's, and all other requests to Storage Buckets.


As pointed out by @Scalar, currently GCP does not support redirects with static website hosting in Google Cloud Storage, so just to add some more detailed information on the proposal to serving content as a backend service, let me share with you some documentation guidelines that might be helpful for you.

Currently, a Cloud Storage bucket can be served as a backend service (in fact a backend bucket) in order for your requests for static content made against a content-based load balancing system to be served by that bucket (while the rest of the requests are handled by your instances; although you can skip that part, as you only need the Cloud Storage service in your configuration).

In order to set up a backend bucket to your load balancer, you can follow the steps detailed in the following documentation page. It assumes that you have previously completed the creation of a content-based load balancer, so you can start from that example. Then, you can set up redirections so that calls to https://example.com/page are redirected to https://anotherexample.com/another-page, and they are finally processed by your load balancing service, which will direct them to your bucket. Redirects can be performed at the application level by means of the web server of your choice, but just to give you a couple of examples, you can do that using NGINX's return or rewrite directives, as explained in their official documentation, or also Apache Server's Redirect or Rewrite rules, as detailed in their documentation to.


While Google Cloud Storage still does not support redirects, the GCP HTTP load balancer now supports it.