Configuring routing rules
The Fastly request routing feature lets you configure rules that route requests to different services based on specific application logic. This lets you break up domain paths and route them to different services within Fastly without needing to write code in Compute or VCL.
How request routing works
In order to route requests, you create a routing configuration that consists of a path and rules. The path is the domain path you want to route requests from. The rules are the criteria that must be met by those incoming requests to route them to the service you specify.
For example, let's say you have a taco restaurant with the domain www.tacolabs.com. For the restaurant's anniversary, you plan on promoting exclusive deals to iPhone customers. You want to be able to route requests to the path www.tacolabs.com/fiesta coming from iPhone users to a specific service. To do this, you:
- Create a new routing configuration called Anniversary Fiesta.
- Identify the path you want to match as
/fiesta. - Define a rule that says IF the
User-Agentheader starts withMozilla/5.0 (iPhone; CPU iPhone), route traffic to the Anniversary Fiesta service. - Define a default rule that routes all other traffic to your regular Taco Labs service.
- Deploy the routing configuration.
- Link the routing configuration to the
tacolabs.comdomain.
Now, Fastly will automatically route requests to the proper service based on the User-Agent header. When the promotion is over, you simply unlink the routing configuration from the domain.
Limitations and considerations
When working with routing rules, keep in mind the following:
- To create a routing configuration on a domain path, the domain must be configured in Domain Management, have a valid TLS certificate, and point to an active service.
- When creating a routing configuration, you must specify a default routing rule which applies to requests when no other rule conditions are met or configured.
- Each path is limited to 20 rules, and each rule can contain up to 5 specific conditions.
Creating a routing configuration
To create a routing configuration, complete the following:
- Log in to the Fastly control panel.
Go to Domains > Routing configuration.
Click Create configuration.
Complete the following fields to define basic information for the configuration, including the domain path you want to act on:
- In the Configuration name field, enter a name for the configuration.
- In the Comment field, enter a comment that describes the changes made in the configuration.
- In the Path value field, enter the path that you want to route requests from.
(Optional) In the Rule section, define the rules that you want to apply to matching requests:
- In the Header field, enter a header.
- From the Operator menu, select an operator to specify how the selected header and value should be compared.
- In the Value field, enter a value for the specified header.
- (Optional) Click Add condition to add another condition.
- In the Select service field, select a service. Requests with data matching your conditions will be routed to this service.
(Optional) Click Add rule to add another rule.
In the Default Rule section, select a service. Requests to the given path that don't match any of the other rule conditions will be routed to this service by default.
Click Save.
When you're ready, deploy the routing configuration and link the routing configuration to a domain.
Deploying a routing configuration
When you're ready to apply your routing configuration to live traffic, deploy the routing configuration. Once a routing configuration is deployed and linked to a domain, incoming requests will be routed based on your rules.
- Log in to the Fastly control panel.
- Go to Domains > Routing configuration.
- Click the name of the routing configuration you want to deploy.
- Click Deploy changes.
- (Optional) Click View diff to review the changes made to the configuration.
- (Optional) In the Deployment comment field, enter a comment that describes the changes being deployed. This can make it easier to identify the changes if you need to roll back later.
- Click Deploy changes.
IMPORTANT: You must link the routing configuration to a domain to complete the process of routing live traffic.
Linking a routing configuration to a domain
By linking a routing configuration to a domain, you set up the process of routing live traffic. If the routing configuration has been deployed, traffic will be routed as soon as you link the domain.
To link a routing configuration to a domain:
- Log in to the Fastly control panel and select Domains from the navigation sidebar.
- Click the name of the domain you want to apply the configuration to.
- From the Domain details page, click the Routing tab.
- From the Link existing configuration field, use the menu to select your routing configuration. Alternately, click the add new configuration link to create a new routing configuration.
- Click Save.
Unlinking a routing configuration from a domain
To unlink a routing configuration from a domain:
- Log in to the Fastly control panel and select Domains from the navigation sidebar.
- Click the name of the domain you want to apply the configuration to.
- From the Domain details page, click the Routing tab.
- Click Unlink to unlink the routing configuration from the domain.
- Click Unlink again to confirm.
Editing routing configurations
To edit a routing configuration:
- Log in to the Fastly control panel.
- Go to Domains > Routing configuration.
- Click the name of the routing configuration you want to edit.
- Click the pencil next to the path that you want to edit.
- Modify the routing rules as needed. Click the trash to the right of a rule or condition to delete it.
- Click Save.
Deleting routing configurations
To delete a specific path and all associated rules on a routing configuration, complete the following:
IMPORTANT: A routing configuration must be unlinked from any services or an error will appear if you try to delete it.
- Log in to the Fastly control panel.
- Go to Domains > Routing configuration.
- Click the name of the routing configuration you want to modify.
- Click the trash to the right of the path you want to delete. This will delete all rules associated with the path.
- Click Delete to confirm you want to delete the path.
To delete a routing configuration, complete the following:
- Log in to the Fastly control panel.
- Go to Domains > Routing configuration.
- Click the trash to the right of the configuration you want to delete.
- If the routing configuration has been activated, enter the name of the configuration to confirm you want to delete it.
- Click Delete.

