Search code examples
google-cloud-platformgoogle-cloud-storagestatic-site

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?


Solution

  • You have to use a Cloud Load Balancer in front of your Google Cloud Storage static site in order to setup redirects.

    You likely want to do this anyway, as it is necessary to serve https content (as opposed to http).

    You can add as many redirects as you want but beware a gotcha - they charge for them. As of today, pricing is:

    For first 5 forwarding rules: $0.025/hour Each additional forwarding rule: $0.01/hour (https://cloud.google.com/vpc/network-pricing#lb)

    That adds up. Like for example, after the first 5 rules, your 6th rule costs you a mere penny per hour. But a penny per hour = $87.60 per year. So imagine you want 100 redirects... oh my.