# Forwarding Policy (Dedicated Load Balancers)

#### Scenarios

You can add forwarding policies to HTTP or HTTPS listeners to forward requests to different backend server groups based on domain names or URLs.

This is suited for applications that are deployed on multiple backend servers and provide multiple types of services such as videos, images, audios, and texts.

A forwarding policy consists of one or more forwarding rules and an action.

- There are two types of forwarding rules: domain name and URL.
- There are two types of actions: forward to a backend server group and redirect to another listener (only HTTP listeners).

#### Constraints and Limitations

- Forwarding policies can be added only to HTTP and HTTPS listeners.
- Redirection to another listener is supported only by HTTP listeners.
- When you add a forwarding policy, note the following:
  - Each URL path must exist on the backend server. If the path does not exist, the backend server will return 404 Not Found.
  - A URL path cannot be configured for two forwarding policies.
  - In the regular expression match, the characters are matched sequentially, and matching ends when any rule is successfully matched. Matching rules cannot overlap with each other.
  - A domain name cannot exceed 100 characters.
- After you add a forwarding policy, the load balancer forwards requests based on the specified domain name or URL:
  - If the domain name or URL in a request matches that specified in the forwarding policy, the request is forwarded to the backend server group you select when you add the forwarding policy.
  - If the domain name or URL in a request does not match that specified in the forwarding policy, the request is forwarded to the default backend server group of the listener.

#### Adding a Forwarding Policy

1. Log in to the management console.
2. In the upper left corner of the page, click and select the desired region and project.
3. Hover on in the upper left corner to display Service List and choose Network > Elastic Load Balancing.
4. Locate the load balancer and click its name.
5. Click Listeners, locate the listener, and click its name.
6. Click Add on the right of Forwarding Policies. Configure the parameters based on Table 1.

   Table 1 Parameters required for configuring a forwarding policy
   Parameter | Description | Example Value
   --- | --- | ---
   Name | Specifies the forwarding policy name. Only letters, digits, underscores (_), hyphens (-), and periods (.) are supported. | forwarding_policy-e370
   Domain Name | Route requests based on the domain name. The domain name in the request must exactly match that in the forwarding policy. Note that you must specify either a domain name or URL. | www.test.com

   URL Matching Rule

   There are three URL matching rules:
   - Exact match

     The request URL is identical to the URL specified in the forwarding policy.

   - Prefix match

     The requested URL starts with the specified URL string.

   - Regular expression match

     The specified URL matches the URL in the request based on the regular expression.

   Exact match

   URL | Specifies the relative URL for traffic routing. The load balancer routes traffic based on the combination of the domain name and URL. The URL can contain only letters, digits, and special characters _~?;@^- %#&$.*+?,=!:|\/()[]{} If Exact match or Prefix match is selected, the URL must start with a slash (/). | /login.php
   Description | Provides supplementary information about the forwarding policy. You can enter up to 255 characters. | -

7. Click Next and add a backend server group.

   Table 2 describes the parameters required for adding a backend server group, and Table 3 describes the parameters required for configuring health check.

8. Click Finish.

#### URL Matching Example

The following table lists how a URL is matched, and Figure 1 shows how a request is forwarded to a backend server group.

Table 2 URL matching
URL Matching Rule | URL | URL in the Forwarding Policy
--- | --- | ---
- | - | /elb/index.html | /elb | /elb[^\s]* | /index.html
Exact match | /elb/index.html | √ | - | - | -
Prefix match | √ | √ | - | -
Regular expression match | √ | - | √ | -

Figure 1 Request forwarding

In this figure, the system first searches for an exact match of the requested URL (/elb_gls/glossary.html). If there is no exact match, the system searches for a prefix match. If a match is found, the request is forwarded to backend server group 2 even if a regular expression match is also found, because the prefix match has a higher priority.

#### Modifying a Forwarding Policy

1. Log in to the management console.
2. In the upper left corner of the page, click and select the desired region and project.
3. Hover on in the upper left corner to display Service List and choose Network > Elastic Load Balancing.
4. Locate the load balancer and click its name.
5. Click Listeners, locate the listener, and click its name.
6. Click on the right of Forwarding Policies.
7. Modify the parameters and click OK.

#### Deleting a Forwarding Policy

You can delete a forwarding policy if you no longer need it.

Deleted forwarding policies cannot be recovered.

1. Log in to the management console.
2. In the upper left corner of the page, click and select the desired region and project.
3. Hover on in the upper left corner to display Service List and choose Network > Elastic Load Balancing.
4. Locate the load balancer and click its name.
5. Click Listeners, locate the listener, and click its name.
6. Click on the right of Forwarding Policies.
7. Click Yes.

Parent topic: Advanced Features of HTTP/HTTPS Listeners