By Dan Bustillos, Cloud Architect 

There’s nothing more frustrating for an end-user than clicking on a webpage and getting the dreaded 404 error. And broken links affect more than the user experience – they can also hurt SEO.

Fortunately, website redirects can forward online traffic from broken URLs to other, more relevant destinations. One way to do this is with Google Cloud’s load balancer. A common and well-documented configuration for load balancers (LBs) within Google Cloud is the supportability for redirecting traffic from 80 to 443 on External HTTPS LBs. 

Let’s outline the details for performing the same configuration on Internal HTTPS Google Cloud load balancers.

Getting Started

To use HTTP-to-HTTPS shared IP redirects, you need to create two load balancers – one for HTTPS traffic and a second for HTTP traffic. Each load balancer will have its own forwarding rule and URL map. However, it will share the same shared front-end IP.

There are several ways to configure this on Google Cloud. We’ll explore two methods via Terraform and Google Cloud SDK.

Creating the Internal HTTPS Load Balancer

The following Terraform code showcases examples of the resources required to provision an internal HTTPS LB on Google Cloud. 

Note: Compute resources are not shown here. It’s assumed compute resources have been previously provisioned.

Now that the internal HTTPS LB is provisioned, we can move forward with the creation of the internal HTTP LB that we will need for the redirect. For this use case, we’ll leverage the Google Cloud SDK commands.

Google Cloud SDK Commands

Creating the Internal HTTP Load Balancer

The following Google Cloud commands show examples of the resources required to provision an internal HTTP LB on Google Cloud to support the HTTP to HTTPS redirect.

  1. Create a new URL map for redirecting traffic. Create a YAML file with traffic redirection.
  2. Import the YAML file to a new URL map.
Google Cloud compute URL-maps import "map-name" — source /url_map.yaml — region us-west1
  1. Create an HTTP proxy, URL map, and HTTP forwarding rule

These commands are run from the command line and leverage the Google Cloud SDK libraries. This is a one-time process that is to run after the deployment of the Terraform code.

Note: The YAML configuration is shown together with the Google Cloud SDK commands for brevity.

The YAML configuration shown with the Google SDK commands

At this point, traffic received by the load balancer on port 80 will be forwarded to 443, e.g., http://myurl.com will appear as https://myurl.com.

I hope you have found this helpful! Thanks for reading. 

Let’s Get Solving With Google Cloud

Explore the power of Google Cloud for your business. Connect with an expert for a custom demo and strategy session.