Use URL maps Stay organized with collections Save and categorize content based on your preferences.
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:
- External Application Load Balancer (global, classic, and regionalmodes)
- Internal Application Load Balancer
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 type | Setting | Meaning |
|---|---|---|
| URL map default | gcloud compute url-maps create
| 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 default | gcloud compute url-maps add-path-matcher
| 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:
- Go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit for the selected load balancer.
- SelectHost and path rules.
- ClickAdd host and path rule.
Fill in theHost field,Paths field, or both, and select abackend service orbackend bucket.
- Enter a fully qualifiedHost name, for example
web.example.com. - Enter the path—for example,
/video. - On theHost and path rules page, in theBackends menu,select an available backend service or backend bucket.
- Enter a fully qualifiedHost name, for example
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.
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
Edit the YAML file with new configuration. For example, if you want toedit an external Application Load Balancer and send all requestswith the path
/videoto a new backend servicecalledvideo-backend-service, you can add tests to the URL mapconfiguration as follows:Existing URL map configuration with a single default
web-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 default
web-backend-serviceand 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-serviceValidate 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'.
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:
- Go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit forthe selected load balancer.
- ClickRouting rules. For a classic Application Load Balancer, this isHost and path rules.
- ClickShow configuration tests.
- ClickAdd configuration test. Add the following test URLs and backends:
- Test host and path 1
example.comandBackendwww-service. - Test host and path 2
example.netandBackendwww-service. - Test host and path 3
example.net/webandBackendwww-service. - Test host and path 4
example.com/videosandBackendvideo-service. - Test host and path 5
example.com/videos/browseandBackendvideo-service. - Test host and path 6
example.net/staticandBackendstatic-service. - Test host and path 7
example.net/static/imagesandBackendstatic-service.
- Test host and path 1
- 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:
- Go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit forthe selected load balancer.
- 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:
- Go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit forthe selected load balancer.
- On theLoad Balancer Details page, view theHost and path rules.
- Click the "X" to the right of a URL map to delete it. The URL map disappears.
- 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:
- Go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit forthe selected load balancer.
- SelectHost and path rules.
- In thePaths field for an existing URL map, click the "x" onthe path matcher's name.
- 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:
- If you're not already on theHost and path rules page, go to theLoad balancing page.
- Click theName of a load balancer.
- On theLoad Balancer Details page, clickEdit forthe selected load balancer.
- SelectHost and path rules.
- In theHosts field for an existing URL map, click the "x" on thehost's name.
- 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.
| Product | URL map features and traffic management guides |
|---|---|
| Global external Application Load Balancer | Load balancer features: Routing and traffic management |
| Classic Application Load Balancer | Load balancer features: Routing and traffic management |
| Regional external Application Load Balancer | Load balancer features: Routing and traffic management |
| Internal Application Load Balancer | Load balancer features: Routing and traffic management |
| Cloud Service Mesh | Cloud Service Mesh features: Routing and 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:
| Product | API documentation |
|---|---|
| External Application Load Balancer | urlMaps |
| Internal Application Load Balancer | regionUrlMaps |
| Cloud Service Mesh | urlMaps |
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
- SeeURL maps overview forinformation on how URL maps work.
- SeeExternal Application Load Balancer overview for information on howURL maps work in external Application Load Balancers.
- SeeInternal Application Load Balancer overview for information on howURL maps work in internal Application Load Balancers.
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.