Use URL maps

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

Before following this guide, familiarize yourself withURL mapconcepts.

Note: This page describes how to configure a specific load balancer component orfeature before or after you've already created a load balancer. Working withspecific components is useful for advanced configurations and necessary for someconfiguration options. Before using the information on this page, know thetypeof Google Cloud load balancerthat you need.

URL maps are used with the following Google Cloud products:

URL maps used with global external Application Load Balancers, regional external Application Load Balancers,internal Application Load Balancers, and Cloud Service Mesh also support several advancedtraffic management features. For more information, seeURL map concepts:Advanced trafficmanagement.

URL map defaults

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

Default typeSettingMeaning
URL map defaultgcloud compute url-maps create

--default-service | --default-backend-bucket

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

--default-service | --default-backend-bucket

The specified default backend service or backend bucket 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). Thehostname 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 tobackend servicesorbackend buckets.Backend buckets are not supported with regional external Application Load Balancers andinternal Application Load Balancers.

Important: If you originally set up your load balancer in theGoogle Cloud console, the URL map's name is the same as your load balancer'sname.

Console

To add a URL map using the Google Cloud console, perform the followingsteps:

  1. Go to theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit for the selected load balancer.
  4. SelectHost and path rules.
  5. ClickAdd host and path rule.
  6. Fill in theHost field,Paths field, or both, and select abackend service orbackend bucket.

    1. Enter a fully qualifiedHost name, for exampleweb.example.com.
    2. Enter the path—for example,/video.
    3. On theHost and path rules page, in theBackends menu,select an available backend service or backend bucket.
    Note: If a backend serviceor backend bucket is not added to the URL map's host andpath rules, the backend serviceor backend bucket remains unused by the load balancer, soyou won't see it on the load balancer'sDetails andEdit pages.
  7. Look for the blue checkmark to the left ofHost and Path Rules andclick theUpdate button.

gcloud

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

gcloud compute url-maps createURL_MAP_NAME \   (--default-backend-bucket=DEFAULT_BACKEND_BUCKET | --default-service=DEFAULT_SERVICE) \   [--descriptionDESCRIPTION] \   [--global | --region=REGION]

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

To create a path matcher, use thegcloud compute url-maps add-path-matchercommand:

gcloud compute url-maps add-path-matcherURL_MAP_NAME \   (--default-backend-bucket=DEFAULT_BACKEND_BUCKET | --default-service=DEFAULT_SERVICE) \   --path-matcher-namePATH_MATCHER \   [--path-rules="PATH=SERVICE or BUCKET"]

This command requires a default backend service or backend bucket to whichit can send unmatched requests. The--path-rules flag defines mappingsbetween request paths and backend services or buckets. The following exampleroutes the request paths/video/ and/video/* to thevideo-servicebackend service:

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

To create a host rule, use thegcloud compute url-maps add-host-rulecommand:

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

For example, the following--hosts value matches requests againstwww.example.com and any subdomain ofaltostrat.com:

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

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

gcloud compute url-maps set-default-serviceURL_MAP_NAME  (--default-backend-bucket=DEFAULT_BACKEND_BUCKET  | --default-service=DEFAULT_SERVICE)[GCLOUD_WIDE_FLAG ...]

Terraform

To create a global URL map, use thegoogle_compute_url_map resource.

# url mapresource "google_compute_url_map" "default" {  name            = "http-lb"  default_service = google_compute_backend_bucket.default.id}

To create a regional URL map, use thegoogle_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}

Validate the URL map configuration

Note: Thegcloud compute url-mapsvalidate command is notsupported for the regional external Application Load Balancer and the internal Application Load Balancer.

Before deploying a URL map, make sure you validate the URL map configuration toensure that the map is routing requests to the appropriate backends as intended.You can do this by adding tests to the URL map configuration. You can experimentwith different URL map rules and run as many tests as needed to be confidentthat the map will route traffic appropriately when it is deployed. Additionally,if any rule changes are needed in the future, you can test those changes beforeactually going live with the new configuration.

Use thegcloud compute url-mapsvalidate command to validateURL map configuration. This command only tests the configuration provided.Irrespective of whether the tests pass or fail, no changes are saved to the deployed URL map. This behavior is unlike other URL map commands(edit,import), which also run the same tests but will actually save the newconfiguration if tests pass. When you want to test a new routing configurationwithout making changes to the deployed URL map, use thevalidatecommand.

Thevalidate command lets you test advanced route configurations such asrouting based on headers and query parameters, HTTP to HTTPS redirects, and URLrewrites.

Console

You cannot use the Google Cloud console to validate URL map configuration.Usegcloud or the REST API instead.

gcloud

To validate your URL map configuration use thegcloud compute url-maps validatecommand.

For the global external Application Load Balancer:

gcloud compute url-maps validate --sourcePATH_TO_URL_MAP_CONFIG_FILE \    --load-balancing-scheme=EXTERNAL_MANAGED \    --global

For the classic Application Load Balancer:

gcloud compute url-maps validate --sourcePATH_TO_URL_MAP_CONFIG_FILE \    --load-balancing-scheme=EXTERNAL \    --global
  • PATH_TO_URL_MAP_CONFIG_FILE: Replace with a path to the filethat contains the URL map configuration for validation.

Validate changes to an existing load balancer's URL map

If you have an existing load balancer that needs changes to the URL map,you can test those configuration changes before making them live.

  1. Export the load balancer's existing URL map to a YAML file.

    gcloud compute url-maps exportURL_MAP_NAME \   --destinationPATH_TO_URL_MAP_CONFIG_FILE \   --global
  2. Edit the YAML file with new configuration. For example, if you want toedit an external Application Load Balancer and send all requestswith the path/video to a new backend servicecalledvideo-backend-service, you can add tests to the URL mapconfiguration as follows:

    Existing URL map configuration with a single defaultweb-backend-service:

     kind: compute#urlMap name:URL_MAP_NAME defaultService: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service

    Edited URL map configuration with added path matcher and tests for boththe defaultweb-backend-service and the newvideo-backend-servicebackend service:

    kind:compute#urlMapname:URL_MAP_NAMEdefaultService:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-servicehostRules:-hosts:-'*'pathMatcher:pathmappathMatchers:-defaultService:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-servicename:pathmappathRules:-paths:-/video-/video/*service:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/video-backend-servicetests:-description:Test routing to existing web servicehost:foobarpath:/service:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/web-backend-service-description:Test routing to new video servicehost:foobarpath:/videoservice:https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendService/video-backend-service
  3. Validate the new configuration.

    gcloud compute url-maps validate --sourcePATH_TO_URL_MAP_CONFIG_FILE

    If all tests pass successfully, you should see a success message such as:

    Successfully validated [https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/urlMaps/URL_MAP_CONFIG_FILE_NAME]

    If the tests fail, an error message appears. Make the required fixes tothe URL map config file and try validating again.

    Error: Invalid value for field 'urlMap.tests': ''.Test failure: Expect URL 'HOST/PATH' to map to service 'EXPECTED_BACKEND_SERVICE', but actually mapped to 'ACTUAL_BACKEND_SERVICE'.
  4. Once you know that the new configuration works and does not impact yourexisting setup, you can import it into the URL map. Note that this stepalso deploys the URL map with the new configuration.

    gcloud compute url-maps importURL_MAP_NAME \   --sourcePATH_TO_URL_MAP_CONFIG_FILE \   --global

Add tests to a URL map

Note: Adding tests to URL maps is not supported for theregional external Application Load Balancer and the internal Application Load Balancer.

You can add configuration tests to a URL map to ensure that your URL map routesrequests to the backend services or backend buckets as intended.

This section describes how to add tests to a URL map that has already beendeployed. If you want to test new changes to a URL map without actuallydeploying the map, seeValidate URL map configuration.

When you edit your URL map, the tests run, and an error message appears if atest fails:

Error: Invalid value for field 'urlMap.tests': ''.Test failure: Expect URL 'HOST/PATH' to map to service 'EXPECTED_BACKEND_SERVICE', but actually mapped to 'ACTUAL_BACKEND_SERVICE'.

Adding tests to URL maps is optional.

Console

To run tests from the Google Cloud console:

  1. Go to theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit forthe selected load balancer.
  4. ClickRouting rules. For a classic Application Load Balancer, this isHost and path rules.
  5. ClickShow configuration tests.
  6. ClickAdd configuration test. Add the following test URLs and backends:
    • Test host and path 1example.com andBackendwww-service.
    • Test host and path 2example.net andBackendwww-service.
    • Test host and path 3example.net/web andBackendwww-service.
    • Test host and path 4example.com/videos andBackendvideo-service.
    • Test host and path 5example.com/videos/browse andBackendvideo-service.
    • Test host and path 6example.net/static andBackendstatic-service.
    • Test host and path 7example.net/static/images andBackendstatic-service.
  7. Look for the blue checkmark to the left ofRouting rules andclick theUpdate button. For a classic Application Load Balancer, look forthe blue check next toHost and path rules.

gcloud

To add tests to your URL map using the Google Cloud CLI, use thegcloud compute url-maps editcommand:

gcloud compute url-maps editURL_MAP_NAME

This launches a text editor. For external Application Load Balancers, your tests must usethe following format:

  tests:    - host: example.com    service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/www-service    - host: example.net    service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/www-service    - host: example.com      path: /videos      service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/video-service    - host: example.com      path: /videos/browse      service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/video-service    - host: example.net      path: /web      service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/www-service    - host: example.net      path: /static      service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/static-service    - host: example.net      path: /static/images      service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/static-service

Note that if you don't specify a host in a host rule, then URLs from all hosts(both example.com and example.net) can match. If you do have host rules, thenyou must create rules that match both example.com and example.net.

List URL maps

Console

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

gcloud

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

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 theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit forthe selected load balancer.
  4. View theHost and path rules.

gcloud

To get information about a single URL map using the Google Cloud CLI,use theurl-maps describecommand.

gcloud compute url-maps describeURL_MAP_NAME

Delete a URL map

You can delete a URL map only after you've deleted all target proxiesthat reference it. For more information, seeDeleting a targetproxy.

Console

To delete a URL map, perform the following steps:

  1. Go to theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit forthe selected load balancer.
  4. On theLoad Balancer Details page, view theHost 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 ofHost and Path Rules andclick theUpdate button.

gcloud

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

gcloud compute url-maps deleteURL_MAP_NAME [--quiet]

Delete a path matcher

Console

To delete a path matcher, perform the following steps:

  1. Go to theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit forthe selected load balancer.
  4. SelectHost and path rules.
  5. In thePaths field for an existing URL map, click the "x" onthe path matcher's name.
  6. Look for the blue checkmark to the left ofHost and Path Rules andclick theUpdate button.

gcloud

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

gcloud compute url-maps remove-path-matcherURL_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 theHost and path rules page, go to theLoad balancing page.

    Go to Load balancing

  2. Click theName of a load balancer.
  3. On theLoad Balancer Details page, clickEdit forthe selected load balancer.
  4. SelectHost and path rules.
  5. In theHosts field for an existing URL map, click the "x" on thehost's name.
  6. Look for the blue checkmark to the left ofHost and Path Rules andclick theUpdate button.

gcloud

To delete a host rule from your URL map, use thegcloud compute url-maps remove-host-rulecommand:

gcloud compute url-maps remove-host-ruleURL_MAP_NAME --host=HOST

For example, to remove a host rule that contains the hostaltostrat.com froma URL map namedmy-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 withload balancers to support several advanced traffic management features, not allof which are supported on the classic Application Load Balancer.

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

ProductURL map features and traffic management guides
Global external Application Load BalancerLoad 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

Classic Application Load BalancerLoad balancer features: Routing and traffic management

Traffic management overview

Setting up a URL redirect

Setting up an HTTP-to-HTTPS redirect

Hostname and path

Header and query parameter-based routing

Regional external Application Load BalancerLoad 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 BalancerLoad 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

Cloud Service MeshCloud Service Mesh features: Routing and traffic management

Advanced traffic management overview

Configuring advanced traffic management

API and gcloud CLI reference

In addition to the Google Cloud console, you can use the API andgcloud CLI to create URL maps.

API

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

ProductAPI documentation
External Application Load BalancerurlMaps
Internal Application Load BalancerregionUrlMaps
Cloud Service MeshurlMaps
Note: In the URL map API,HttpRouteRuleMatch means an instance ofpathMatchers[].routeRules[].matchRules[].

gcloud CLI

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

  • Global:--global
  • Regional:--region=[REGION]

For advanced traffic management, use YAML files and import them with thegcloud compute url-maps importcommand.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.