You need to enable JavaScript to run this app.
Load Balancer

Load Balancer

Copy page
Download PDF
Creating a forwarding rule (Standard edition)
Copy page
Download PDF
Creating a forwarding rule (Standard edition)
This topic describes how to create forwarding rules for Standard Edition ALB instances in the console.​
Components​
A forwarding rule consists of a forwarding condition and a forwarding action.​
​
Components​
Notes​
Forwarding condition​
The forwarding condition is used to filter requests. A forwarding rule can contain one or more forwarding conditions.​
  • The types of forwarding conditions supported by the Standard ALB instance include Domain name, URL path, HTTP header, HTTP request method, query string, Cookie, and SourceIP.​
  • Configuration: Different types of forwarding conditions can be configured individually or in combination.​
  • When multiple forwarding conditions are configured together, the relationship between them is AND. Example: If you configure both a domain name and a URL path in a single rule, a request is considered a match only if it matches both the specified domain name and URL path.​
  • Multiple values are allowed for the same forwarding condition, and the relationship between these values is OR. Example: If you configure multiple values for the Domain Name condition, the condition is satisfied if the request's domain name matches any one of those values.​
Forwarding action​
​
The forwarding action determines how a request is forwarded.​
  • Standard edition ALB instances support the following forwarding actions: Forward to, Redirect to, Rewrite, Rate Limit, Return Fixed Response, Cross-domain, and Write Header.​
  • Rate limiting and Rewrite must be used together with either Forward to or Redirect to.​
  • Rate limiting, Rewrite, and Forward to can also be used together. When multiple forwarding actions are configured in combination, the relationship between them is AND.​
​
Matching​
Upon receiving a client request, ALB performs matching sequentially according to the priority of the forwarding rules, from highest to lowest.​
  • Priority exists among forwarding rules under the same listener:​
  • The default forwarding rule has the lowest priority, and its priority cannot be adjusted.​
  • The priority of custom forwarding rules can be adjusted.​
  • A smaller priority number indicates a higher priority. In the forwarding rule list, a rule placed higher up has a higher priority.​
  • By default, a newly created forwarding rule has a higher priority than existing rules.​
  • How to adjust custom forwarding rule priority:​
  • Method 1: Enter a value. Click Set priority, enter the target value, then click Save. The system will automatically adjust the rule's position.​
  • Method 2: Drag and drop. Hover the mouse over the settings icon in the upper right corner of the rule card, then drag the card to the target position. In the dialog box, confirm the prompt, then click Save.​
For details on the forwarding rule matching process, see Forwarding rule matching (Standard edition).​
Prerequisites​
Use limits​
  • Except for the default forwarding rule, each instance can create up to 100 forwarding rules.​
  • Each forwarding rule must satisfy the following constraints:​
  • The number of forwarding conditions must be between 1 and 10 (inclusive).​
  • Only one of the three forwarding actions - Forward to, Redirect to, or Return fixed response - can be configured, and this action must be placed at the end of the action list.​
  • The rate-limiting action must be placed at the top of the forwarding action list.​
  • Rate limiting and Rewrite must be used together with either Forward to or Redirect to. Cross-origin and Write Header must be used together with Forward to, Redirect to, or Return fixed response.​
  • The order of forwarding actions can be adjusted using the up (↑) and down (↓) arrows on the page.​
Procedures​
  1. Log in to the ALB console.​
  1. On the Instance management page, find the ALB instance to configure, then under the Actions in the column, click Listener.​
  1. On the Listener information tab, find the listener to configure and under Actions in the column, then click Edit forwarding rules.​
  1. On the Forwarding rules tab, click Add forwarding rules.​
  1. On the Add forwarding rules page, configure the related parameters according to the instructions below.​
  1. Configure forwarding conditions​
  • ​
    Parameters​
    Notes​
    Domain​
    Specify one or more domain names. When you specify multiple domain names, the relationship between these domain names is OR.​
    • Domain name is case-insensitive. The specified domain must comply with the following specifications:​
    • Only allow English letters, numbers, and the following special characters: .- _ *.​
    • Must contain at least one half-width period (.), but cannot begin or end with a half-width period (.).​
    • Supports 1 to 128 characters.​
    • A domain name can be an exact domain name or a wildcard domain name:​
    • Exact domain: Must comply with domain name specifications.​
    • Wildcard domain​
    • An asterisk (*) can represent one or more characters.​
    • The asterisk (*) must be at the beginning or the end of the domain name.​
    • A domain name can contain at most one asterisk (*).​
    • Characters other than a period (.) are not allowed immediately before or after the asterisk (*).​
    • Example:​
    • Valid domain examples: www.test.com, *.com, www.test.*.​
    • Invalid domain examples: *aaa.com, www.*.com.​
    warning​
    A wildcard domain name only matches domain names at the same level. For example, *.example.com matches www.example.com but not example.com.​
    URL path​
    Specify one or more paths. When you specify multiple paths, the relationship between these paths is OR.​
    • Path length supports 0 to 128 characters.​
    • Supports exact paths and regular expressions:​
    • Exact path​
    • Format:​
    • The value must start with a forward slash (/).​
    • Only letters, numbers, and the following special characters are permitted: - _ / .% ?# * & =.​
    • Consecutive forward slashes are not allowed.​
    • By default, exact matching is used. The asterisk (*) and question mark (?) can also be used as wildcards.​
    • Examples:​
    • Exact match: If the path is configured as /api/v1/users, a request to /api/v1/users will match successfully.​
    • Prefix match: If the path is configured as /api/*, requests to /api/v1/users and /api/v2 will both match successfully.​
    • Regular expression​
    • Format:​
    • The value must start with a tilde (~), and the tilde can only appear once at the beginning.​
    • Only letters, numbers, and the following special characters are allowed: .- _ / = ?~ ^ * $ : ( ) [ ] + |.​
    • ~ at the beginning indicates case-sensitive matching. ~* at the beginning indicates case-insensitive matching.​
    • Example: ~^/api/v[0-9]+/users/.*$​
    HTTP header​
    Set HTTP headers. HTTP header is expressed in the form of key-value pairs. Each key can correspond to multiple values, and the relationship between these values is OR. Within the same forwarding rule, key must be unique. If you need to add multiple HTTP headers, click Add forwarding condition.​
    • Requirements for the entered key:​
    • Only English letters, numbers, hyphens (-), and underscores (_) are allowed.​
    • Cannot be Cookie or Host.​
    • Supports 1 to 40 characters.​
    • Requirements for the entered value:​
    • Can contain printable ASCII characters.​
    • Cannot start or end with a space.​
    • Supports 1 to 128 characters.​
    HTTP request method​
    Select one or more HTTP request methods. When you select multiple request methods, the relationship between these methods is OR.​
    The following request methods are supported: HEAD, GET, POST, OPTIONS, PUT, PATCH, DELETE.​
    Query string​
    Set query string. The query string is expressed in the form of key-value pairs. Within the same forwarding condition, the relationship between multiple key-value pairs is OR. Across different forwarding conditions, the relationship between key-value pairs is AND. Within the same forwarding rule, key-value pairs must be unique.​
    • Requirements for the entered key:​
    • Allowed characters: lowercase English letters, numbers, and printable special characters except #[]{}\|<>&".​
    • Cannot contain spaces.​
    • Supports 1 to 100 characters.​
    • Requirements for the entered value:​
    • Allowed characters: lowercase English letters, numbers, and printable special characters except #[]{}\|<>&".​
    • Cannot contain spaces.​
    • Supports 1 to 128 characters.​
    Cookie​
    Add one or more cookies.​
    • The cookie key must comply with the following specifications:​
    • The key for the cookie cannot be empty.​
    • Supports 1 to 100 characters.​
    • Supports visible characters, the wildcard asterisk (*), and the half-width question mark (?). If letters are used, they must be lowercase.​
    • Does not support spaces and ;#[]{\|<>&".​
    • Cannot consist entirely of * and ?.​
    • The cookie value must comply with the following specifications:​
    • Cookie value cannot be empty.​
    • Supports 1 to 100 characters.​
    • Supports visible characters, the wildcard asterisk (*), and the half-width question mark (?). If letters are used, they must be lowercase.​
    • Does not support spaces and ;#[]{\|<>&".​
    • Cannot consist entirely of * and ?.​
    tip​
    This feature is currently in Beta stage. For trial requests, please contact your account manager.​
    SourceIP​
    Only requests that match the SourceIP condition will be forwarded.​
    • Only supports entering IPv4 addresses/IPv4 address ranges, and the IP address must include a mask.​
    • Does not support address ranges of the 0.0.0.0/x type, where x is any number.​
    • If a forwarding condition includes SourceIP, only requests whose source matches the specified IP address or CIDR block will match this rule.​
    • A single rule supports a maximum of 5 values for the SourceIP condition type.​
    tip​
    This feature is currently in Beta stage. For trial requests, please contact your account manager.​
    ​
  1. Configure forwarding actions​
  • Forward to​
  • The ALB forwards the request to the server group you specify.​
  • ​
    Parameters​
    Notes​
    Server group​
    Select the server group to which requests are forwarded.​
    • You can only select server groups that are in the same VPC as the current ALB instance.​
    • When a request meets the specified forwarding condition(s), it will be forwarded to the server group.​
    • In a single custom forwarding rule, you can add up to 5 server groups.​
    • When multiple server groups are added, you can set a weight for each server group individually. The default weight for a server group is 100. You can modify the weight to any value from 0 to 100. When a server group's weight is set to 0, it indicates that the ALB will not forward client traffic to that server group. For more information, see Server group weight.​
    Session persistence among server groups​
    Enable session persistence among server groups.​
    • This parameter is only displayed when you have configured multiple server groups.​
    • Session persistence between server groups is disabled by default. After enabling this feature, you need to set a timeout period. The valid range for the timeout is 1 to 86400 (seconds), with a default value of 1000. Unit: Second.​
    For more information, see Session persistence between server groups.​
    ​
  • Redirect to​
  • The ALB redirects the request. For example, redirect an HTTP request to an HTTPS request, or redirect requests from the original domain to a new domain.​
tip​
  • To redirect all requests of a listener, configure the forwarding rules as follows: leave the domain field empty, set the path to ~/, and select Redirect as the forwarding action.​
  • When configuring redirect parameters, modify at least one of the following parameters to avoid redirect loops: Protocol, Domain, Port, or URL. When the request protocol differs from the redirect protocol, ensure the correct port is configured and update relevant server settings to avoid redirection failure.​
  • If the value of the Content-Length header in the request exceeds the maximum request body size (client_max_body_size) set on the listener, the ALB will directly return a 413 status code to the client and will not execute the redirection action. For information on how to adjust the maximum request body size on a listener, see Custom configuration.​
  • ​
    Parameters​
    Notes​
    Agreement​
    Select the protocol for redirection. The protocol can be HTTPS or HTTP.​
    When a request meets the specified forwarding condition(s), it will be redirected.​
    Domain​
    Specify the domain name to which the request is redirected.​
    • If you do not specify a domain name, the redirected domain name will be the same as the request's domain name.​
    • Domains must comply with the following specifications:​
    • Only English letters, numbers, half-width periods (.), and hyphens (-) are allowed.​
    • Must contain at least one half-width period (.), but cannot begin or end with a half-width period (.).​
    • Neither the beginning nor the end of each level of a domain name can be a hyphen (-).​
    • A maximum of 128 characters is allowed.​
    • Must be an exact domain name that complies with domain name specifications, e.g., www.test.com.​
    Port​
    Specify the port to which the request is redirected. Port range: 1 to 65535.​
    If you do not specify a port, the redirected port will be the same as the request port.​
    URI​
    Specify the path to which the request is redirected.​
    • If you do not specify a path, the redirected path will be the same as the request path.​
    • The path must comply with the following specifications:​
    • Must start with a forward slash (/).​
    • A maximum of 128 characters is allowed.​
    • Only English letters, numbers, and the following special characters are allowed: - _ / .% ?# &=. Consecutive forward slashes are not allowed.​
    • Supports exact paths and regular expressions:​
    • Exact path​
    • Format:​
    • Must start with a forward slash (/).​
    • Only letters, numbers, and the following special characters are permitted: - _ / .% ?# * & =. Consecutive forward slashes are not allowed.​
    • By default, exact matching is used. The asterisk (*) and question mark (?) can also be used as wildcards.​
    • A maximum of 128 characters is allowed.​
    • Examples:​
    • Exact match: If the path is configured as /api/v1/users, a request to /api/v1/users will match successfully.​
    • Prefix match: If the path is configured as /api/*, requests to /api/v1/users and /api/v2 will both match successfully.​
    • Regular expression​
    • Format:​
    • The value must start with a tilde (~), and the tilde can only appear once at the beginning.​
    • Only letters, numbers, and the following special characters are allowed: .- _ / = ?~ ^ * $ : ( ) [ ] + |.​
    • ~ at the beginning indicates case-sensitive matching. ~* at the beginning indicates case-insensitive matching.​
    • Example: ~^/api/v[0-9]+/users/.*$​
    • If you use parentheses ( ) in the path specified in the forwarding condition to create capture groups, you can use placeholders like ${1}, ${2}, ${3}, etc., in the path specified in the forwarding action. These placeholders correspond sequentially to the capture groups (${1} for the first group, ${2} for the second, and so on). When processing the request, ALB replaces these placeholders with the path fragments matched by the corresponding capture groups. Example: Suppose the path in the forwarding condition is /volc/(.*)/(.*)/aaa, and the path in the forwarding action is /${1}/${2}. If the request path is /volc/ccc/bbb/aaa, ALB will replace ${1} with ccc and ${2} with bbb. The final redirect path is /ccc/bbb.​
    Query​
    Specify the query string of the redirect target URL, which is the part after the ? in the URL, e.g., xxx=xxx. Example: city=beijing in www.test.com/test/?city=beijing.​
    • If no query string is specified, the redirect automatically uses the query string from the original request.​
    • Custom query strings must meet the following specifications:​
    • Maximum length: 128 characters;​
    • They must not contain spaces or any of the characters #[]{}\|<>";​
    • Only lowercase English letters are allowed.​
    Status code​
    Select a status code to indicate the redirection response status.​
    The default status code is 301, indicating that the requested resource has been permanently moved to a new location. ALB supports status codes 301, 302, 307, and 308.​
    ​
  • Rewrite​
  • The ALB rewrites the request path or domain name and then forwards the request to backend servers using the new path or domain.​
  • ​
    Parameters​
    Notes​
    Path​
    Specify the new path. When a request meets the specified forwarding condition(s), it will be forwarded to the new path. The path must comply with the following specifications:​
    • The path length cannot exceed 128 characters.​
    • The path must start with a forward slash (/).​
    • The path can only include English letters, numbers, and the following special characters: - _ / .% ?# &=. Consecutive forward slashes are not allowed.​
    • If you use parentheses ( ) in the path specified in the forwarding condition to create capture groups, you can use placeholders like ${1}, ${2}, ${3}, etc., in the path specified in the forwarding action. These placeholders correspond sequentially to the capture groups (${1} for the first group, ${2} for the second, and so on). When processing the request, ALB replaces these placeholders with the path fragments matched by the corresponding capture groups. Example: Suppose the path in the forwarding condition is /volc/(.*)/(.*)/aaa, and the path in the forwarding action is /${1}/${2}. If the request path is /volc/ccc/bbb/aaa, ALB will replace ${1} with ccc and ${2} with bbb. The final forwarding path is /ccc/bbb.​
    Domain​
    Specify the new domain name. When a request meets the specified forwarding condition(s), it will be forwarded to the new domain name. Domains must comply with the following specifications:​
    • If left blank, it defaults to being consistent with the original request's domain name.​
    • The hostname must be 3 to 128 characters in length, and supports lowercase letters (a–z), numbers, hyphens (-), periods (.), as well as wildcard asterisks (*), equals signs (=), tildes (~), underscores (_), plus signs (+), backslashes (\), carets (^), exclamation marks (!), dollar signs ($), ampersands (&), vertical bars (|), parentheses (()), square brackets ([]), and question marks (?).​
    • A hostname must contain at least one period (.), which cannot appear at the beginning or end.​
    • The rightmost domain label can only contain letters and the wildcard asterisk (*); it cannot contain digits or hyphens (-). The leftmost domain label is allowed to be an asterisk (*).​
    • A hyphen (-) cannot appear at the beginning or end of any domain tag. The wildcard asterisk (*) and question mark (?) can appear anywhere in a domain label.​
    ​
  • Rate limiting​
  • When the number of requests exceeds the configured QPS, the ALB will reject requests that exceed the limit.​
  • ​
    Parameters​
    Notes​
    QPS​
    Configure QPS.​
    • When the number of client requests exceeds the configured QPS, ALB will reject the exceeding requests and return a 503 status code to the client.​
    • The rate limiting feature is disabled by default. After enabling this feature, you need to enter the QPS value. Value range: 100-150000.​
    ​
  • Return fixed response​
  • The ALB directly returns your custom response to the client and does not forward the client request to the backend server.​
  • ​
    Parameters​
    Notes​
    HTTP response code​
    Set the HTTP response status code. Allowed response status codes include 2xx, 4xx, and 5xx. The x can be any number from 0 to 9.​
    Response body type​
    Set the response body type. The response returned by ALB to the client will include the Content-Type header.​
    Allowed response body types include: text/plain, text/css, text/html, application/javascript, and application/json.​
    Response body​
    Optional. Configure the response body. Maximum of 1024 characters is supported.​
    ​
  • Cross-domain​
  • Cross-domain refers to any difference in the protocol, domain, or port between the client's request and the address of the page returned by the server.​
tip​
This feature is currently in Beta stage. For trial requests, please contact your account manager.​
  • ​
    Parameters​
    Notes​
    Allowed sources​
    Set the site allowed to access server resources via browser.​
    • Supports configuring the wildcard "*", and allows multiple values separated by commas, up to 32 values.​
    • Each value must start with http:// or https://, followed by a domain name or a single-level wildcard domain (*.test.abc.example.com).​
    • Each value supports setting a port, with a port range of 1 to 65535.​
    Allowed methods​
    Select the allowed HTTP method for cross-origin access.​
    • Supports GET, POST, PUT, DELETE, HEAD, OPTIONS, and PATCH.​
    • Multiple selections are supported.​
    Allowed request headers​
    Allowed headers for cross-origin requests (excluding default browser headers)​
    • Can be configured with the wildcard "*", and allows multiple values separated by commas, up to 32 values.​
    • Each value only allows uppercase and lowercase letters, numbers, and hyphens "-" and underscores "_" that are not at the beginning or end, with a maximum length of 32 characters.​
    Allowed response headers​
    Response headers allowed to be accessed by browsers and JavaScript scripts​
    • Can be configured with the wildcard "*", and allows multiple values separated by commas, up to 32 values.​
    • Each value only allows uppercase and lowercase letters, numbers, and hyphens "-" and underscores "_" that are not at the beginning or end, with a maximum length of 32 characters.​
    Allow credentials​
    Allow credentials for cross-origin requests​
    • Allow​
    • Deny​
    Browser cache duration​
    Set the browser cache duration. Value range: -1 to 172,800 seconds.​
    ​
  • Write Header​
  • Add a key: value pair to the request header, which will be sent to the backend server along with the request.​
  • ​
    Parameters​
    Notes​
    Key​
    Enter the header field name.​
    • The length must be 1 to 40 characters, and supports uppercase and lowercase letters (a–z), numbers, underscores (_), and hyphens (-).​
    • Field names must be unique.​
    • Regardless of case, the following header names are not supported: x-real-ip, x-forwarded-for, x-forwarded-proto, x-alb-waf-requestid, x-alb-waf-real-port, upgrade, connection, x-vport, x-vip, x-clb-cluster, x-toutiao-lb-ip, x-vni, content-length, transfer-encoding, keep-alive, host, cookie, authority.​
    Value type​
    Header field content type. Valid values:​
    • Custom: You define the custom header field content.​
    • System defined: The system defines the header field content.​
    Value​
    Enter the header field content.​
    • When Value Type is set to System-defined, the system automatically writes content to the header. The available options are as follows:​
    • $remote_addr (client IP address)​
    • $remote_port (client port)​
    • $Scheme (request protocol)​
    • $load_balancer_id (ALB instance ID)​
    • $Vport (listening port)​
    • $endpoint_id (endpoint ID)​
    tip​
    $endpoint_id parameter is in invite-only beta. For trial requests, please contact your account manager.​
    • When Value Type is set to Custom, you can define the header content yourself, subject to the following specifications:​
    • Length limit: 1-128 characters.​
    • Supports wildcard asterisks (*), question marks (?), and printable ASCII characters with code values in the range ch >= 32 && ch < 127. The characters $ and " are not supported.​
    • No leading or trailing spaces.​
    • Must not end with \.​
    ​
  1. Other parameters​
  • ​
    Parameters​
    Notes​
    Description​
    Enter the description of the forwarding rules. The description must comply with the following specifications:​
    • Cannot exceed 255 characters.​
    • Must start with an English letter or a Chinese character.​
    • Can only contain English letters, Chinese characters, numbers, spaces, and the following special characters: ,._=-,。.​
    ​
  1. Click Associate/Disassociate to complete the action.​
​
​
​
​
Last updated: 2026.07.31 15:21:37