Use URL maps

This guide shows you how to configure Trusted Cloud URL maps. A URL map is a set of rules for routing incoming HTTP(S) requests to specific backend services. A minimal URL map matches all incoming request paths (/*).

Before following this guide, familiarize yourself with URL map concepts.

URL maps are used with the following Trusted Cloud products:

URL maps used with regional external Application Load Balancers and regional internal Application Load Balancers also support several advanced traffic management features. For more information, see URL map concepts: Advanced traffic management.

URL map defaults

URL maps have two defaults, as described in the following table.

Default type Setting Meaning
URL map default gcloud compute url-maps create

--default-service

The specified default backend service is used if none of the path matchers or host rules match the incoming URL.
Path matcher default gcloud compute url-maps add-path-matcher

--default-service

The specified default backend service is used if the URL's path matches a path matcher, but none of the specified --path-rules match.

Host rules

A host rule defines a set of hosts to match requests against.

In a host rule, the hostname must be a fully qualified domain name (FQDN). The hostname can't be an IPv4 or IPv6 address. For example:

  • Works: example.com
  • Works: web.example.com
  • Works: *.example.com
  • Doesn't work: 35.244.221.250

Configure URL maps

A URL map can send traffic to backend services.

Console

To add a URL map using the Trusted Cloud console, perform the following steps:

  1. Go to the Load balancing page.

    Go to Load balancing

  2. Click the Name of a load balancer.
  3. On the Load Balancer Details page, click Edit for the selected load balancer.
  4. Select Host and path rules.
  5. Click Add host and path rule.
  6. Fill in the Host field, Paths field, or both, and select a backend service.

    1. Enter a fully qualified Host name, for example web.example.com.
    2. Enter the path—for example, /video.
    3. On the Host and path rules page, in the Backends menu, select an available backend service.
  7. Look for the blue checkmark to the left of Host and Path Rules and click the Update button.

gcloud

To add a URL map using the Google Cloud CLI, use the url-maps create command:

gcloud compute url-maps create URL_MAP_NAME \
   (--default-service=DEFAULT_SERVICE) \
   [--description DESCRIPTION] \
   [--region=REGION]

For regional external Application Load Balancers and internal Application Load Balancers, make sure to include the --region flag when you create the URL map.

To create a path matcher, use the gcloud compute url-maps add-path-matcher command:

gcloud compute url-maps add-path-matcher URL_MAP_NAME \
   (--default-service=DEFAULT_SERVICE) \
   --path-matcher-name PATH_MATCHER \
   [--path-rules="PATH=SERVICE"]

This command requires a default backend service to which it can send unmatched requests. The --path-rules flag defines mappings between request paths and backend services. The following example routes the request paths /video/ and /video/* to the video-service backend service:

--path-rules="/video=video-service,/video/*=video-service"

To create a host rule, use the gcloud compute url-maps add-host-rule command:

gcloud compute url-maps add-host-rule URL_MAP_NAME \
    --hosts=[HOSTS] --path-matcher-name=PATH_MATCHER

For example, the following --hosts value matches requests against www.example.com and any subdomain of altostrat.com:

--hosts=[*.altostrat.com,www.example.com]

To change the default service of a URL map, use the url-maps set-default-service command:

gcloud compute url-maps set-default-service URL_MAP_NAME
  (--default-service=DEFAULT_SERVICE)[GCLOUD_WIDE_FLAG ...]

Terraform

To create a regional URL map, use the google_compute_region_url_map resource.

resource "google_compute_region_url_map" "default" {
  name            = "regional-l7-xlb-map"
  region          = "us-west1"
  default_service = google_compute_region_backend_service.default.id
}

List URL maps

Console

You cannot list all of your URL maps in the Trusted Cloud console.

gcloud

To display a list of URL maps using the Google Cloud CLI, use the url-maps list command.

gcloud compute url-maps list

Get information about a URL map

Console

To get information about a URL map, perform the following steps:

  1. Go to the Load balancing page.

    Go to Load balancing

  2. Click the Name of a load balancer.
  3. On the Load Balancer Details page, click Edit for the selected load balancer.
  4. View the Host and path rules.

gcloud

To get information about a single URL map using the Google Cloud CLI, use the url-maps describe command.

gcloud compute url-maps describe URL_MAP_NAME

Delete a URL map

You can delete a URL map only after you've deleted all target proxies that reference it. For more information, see Deleting a target proxy.

Console

To delete a URL map, perform the following steps:

  1. Go to the Load balancing page.

    Go to Load balancing

  2. Click the Name of a load balancer.
  3. On the Load Balancer Details page, click Edit for the selected load balancer.
  4. On the Load Balancer Details page, view the Host and path rules.
  5. Click the "X" to the right of a URL map to delete it. The URL map disappears.
  6. Look for the blue checkmark to the left of Host and Path Rules and click the Update button.

gcloud

To delete a URL map using the Google Cloud CLI, use the url-maps delete command. Before you can delete a URL map, any target HTTP proxies that reference the URL map must first be deleted.

gcloud compute url-maps delete URL_MAP_NAME [--quiet]

Delete a path matcher

Console

To delete a path matcher, perform the following steps:

  1. Go to the Load balancing page.

    Go to Load balancing

  2. Click the Name of a load balancer.
  3. On the Load Balancer Details page, click Edit for the selected load balancer.
  4. Select Host and path rules.
  5. In the Paths field for an existing URL map, click the "x" on the path matcher's name.
  6. Look for the blue checkmark to the left of Host and Path Rules and click the Update button.

gcloud

To delete a path matcher, use the gcloud compute url-maps remove-path-matcher command:

gcloud compute url-maps remove-path-matcher URL_MAP_NAME \
   [--path-matcher-name PATH_MATCHER]

Delete a host rule

Console

To delete a host rule, perform the following steps:

  1. If you're not already on the Host and path rules page, go to the Load balancing page.

    Go to Load balancing

  2. Click the Name of a load balancer.
  3. On the Load Balancer Details page, click Edit for the selected load balancer.
  4. Select Host and path rules.
  5. In the Hosts field for an existing URL map, click the "x" on the host's name.
  6. Look for the blue checkmark to the left of Host and Path Rules and click the Update button.

gcloud

To delete a host rule from your URL map, use the gcloud compute url-maps remove-host-rule command:

gcloud compute url-maps remove-host-rule URL_MAP_NAME --host=HOST

For example, to remove a host rule that contains the host altostrat.com from a URL map named my-map, you would run the following command:

gcloud compute url-maps remove-host-rule my-map --host altostrat.com

Traffic management guides

Not all URL map features are available for all products. URL maps are used with load balancers to support several advanced traffic management features.

Use the following table to learn about the URL map features for management works.

Product URL map features and traffic management guides
Regional external Application Load Balancer Load balancer features: Routing and traffic management

Traffic management overview

Setting up traffic management

Setting up a URL redirect

Setting up an HTTP-to-HTTPS redirect

Hostname and path

Routing requests

Cookies

Internal Application Load Balancer Load balancer features: Routing and traffic management

Traffic management overview

Setting up traffic management

Setting up URL redirects

Setting up HTTP-to_HTTPS redirects

Cookies

Hostname and path

API and gcloud CLI reference

In addition to the Trusted Cloud console, you can use the API and gcloud CLI to create URL maps.

API

For descriptions of the properties and methods available to you when working with URL maps through the REST API, see the following:

Product API documentation
External Application Load Balancer urlMaps
Internal Application Load Balancer regionUrlMaps

gcloud CLI

For the Google Cloud CLI in the Google Cloud CLI, see the following:

  • Regional: --region=[REGION]

For advanced traffic management, use YAML files and import them with the gcloud compute url-maps import command.

What's next