All Products
Search
Document Center

Server Load Balancer:Configure domain name- and URL path-based forwarding rules for ALB

Last Updated:Mar 25, 2026

This topic describes how to configure domain name- and URL path-based forwarding rules for Application Load Balancer (ALB) listeners, and how to configure advanced URL path-based forwarding rules for rewrites and redirects.

Domain name-based forwarding rules

You can specify a specific domain name, a wildcard domain name, or a regular expression as the match condition in a domain name-based forwarding rule. For more information about how to create a forwarding rule, see the Add a forwarding rule section of the Manage forwarding rules for a listener topic.

Note

ALB evaluates forwarding rules sequentially according to their priority number; it does not automatically sort them by domain specificity.

If a listener contains both an exact-match domain rule (e.g., app.example.com) and a wildcard domain rule (e.g., *.example.com), you must assign a higher priority (a lower number) to the exact-match rule. This ensures that traffic to the specific domain is matched first.

This behavior is different from Classic Load Balancer (CLB), which automatically sorts rules based on specificity (Exact Match > Narrower Wildcard > Broader Wildcard).

Match type

Description

Exact match and wildcard match

  • Match conditions

    • Exact match: The requested domain name must be the same as the specified domain name.

    • Wildcard match: The requested domain name must match the wildcard pattern of the specified domain name.

  • Requirements

    The domain name must be 3 to 128 characters in length and can contain only letters, digits, and the following special characters: . - ? = ~ _ + \ ^ * ! $ & | ( ) [ ]. You can use asterisks (*) and question marks (?) as wildcard characters.

  • Examples

    Requested domain name: www.example.com

    • Exact match: The requested domain name is matched only if www.example.com is specified in the forwarding rule.

    • Wildcard match: The requested domain name is matched if *.example.com or www.example.* is specified in the forwarding rule.

Regular expression match

  • Match conditions

    The requested domain name must match the specified regular expression.

  • Requirements

    The domain name must be 3 to 128 characters in length and can contain only letters, digits, and the following special characters: . - ? = ~ _ - + \ ^ * ! $ & | ( ) [ ].

  • Examples

    Requested domain name: www.example.com

    Case-insensitive regular expression: The requested domain name is matched if ^www.example.com$ is specified in the forwarding rule.

URL-based forwarding rules

You can specify a specific URL, a wildcard URL, or a regular expression as the match condition in a URL-based forwarding rule. For more information about how to create a forwarding rule, see the Add a forwarding rule section of the " Manage forwarding rules for a listener" topic.

Match type

Description

Exact match and wildcard match

  • Match conditions

    • Exact match: The requested path must be the same as the specified path.

    • Wildcard match: The requested path must match the wildcard pattern of the specified path.

  • Requirements

    The path must start with a forward slash (/) and can contain only letters, digits, and the following special characters: $ - _ . + / & ~ @ :. You can use asterisks (*) and question marks (?) as wildcard characters.

  • Examples

    Requested path: /example/text

    • Exact match: The requested path is matched only if /example/text is specified in the forwarding rule.

    • Wildcard match: The requested path is matched if /example/* is specified in the forwarding rule.

    Note

    The path matching rules of ALB are different from the rules of NGINX. ALB does not support the longest prefix match rule.

    For example, a common path configured for NGINX is location /abc. The longest prefix match rule is used to match the path. To perform longest prefix match, ALB uses wildcard characters. You can configure /abc/* in ALB to perform longest prefix match.

Regular expression match

  • Match conditions

    The requested path matches the specified regular expression.

  • Requirements

    The regular expression can contain only letters, digits, and the following special characters: . - _ / = ? ~ ^ * $ : ( ) [ ] + |.

  • Example

    Requested path: /sys/aaa/HOST

    • Case-sensitive regular expression: The requested path is matched if ^/sys/(.*)/HOST$ is specified in the forwarding rule.

    • Case-insensitive regular expression: The requested path is matched if ^/sys/(.*)/host$ is specified in the forwarding rule.

Advanced URL-based forwarding rule settings for rewrites and redirects

If you specify a regular expression as the match condition in a rewrite or redirect rule, the original URL is overwritten by the variables that match the regular expression. For more information about how to create a forwarding rule, see the Add a forwarding rule section of the Manage forwarding rules for a listener topic.

Note

For more information about how to configure regular expressions in URL-based forwarding conditions, see the URL-based forwarding rules section of this topic.

  • Usage notes

    • You can specify one or more regular expressions as the match conditions in a rewrite or redirect rule and use parentheses ( ) to define them as capture groups. The number of capture groups must be the same as the number of variables in the rewrite or redirect rule.

    • You can use up to three variables (${1}, ${2}, and ${3}) to form the URL that overwrites the original URL. The variables cannot be replaced with other characters.

  • Procedure

    1. URL matching: The client sends a request. The request matches a regular expression that is specified in a forwarding rule.

    2. Extraction and replacement: extracts the content from the capture groups ( ) and writes the content to ${1}, ${2}, and ${3}. The content is used to replace the rewriting or redirection path of the forwarding action.

    3. Splicing: splices the strings that overwrote the variables ${1}, ${2}, and ${3} to form the new URL.

    No.

    Step

    Example

    1

    Configure the forwarding condition and the forwarding action in a forwarding rule.

    • Path in the forwarding condition: /sys/(.*)/(.*)/aaa

    • Path to which requests are rewritten or redirected: /${1}/${2}

    2

    A client request matches the path in the forwarding rule.

    • Requested path: /sys/ccc/bbb/aaa

    • Matched path: /sys/(.*)/(.*)/aaa

    3

    The system extracts values from the regular expression and replaces the variables with the values.

    ccc and bbb are extracted from (.*) in the regular expression and replace the variables ${1} and ${2} in the path to which requests are rewritten or redirected.

    • ${1} is replaced by ccc.

    • ${2} is replaced by bbb.

    4

    The values are concatenated to form the actual path.

    The path received by the backend server is /ccc/bbb.

  • Examples

    You can create forwarding rules in the ALB console based on the usage notes and procedure.

    Example 1: Configure the Rewrite or Forward action

    In this example, a forwarding rule is configured to rewrite the path of requests destined for sys/ccc/bbb/aaa to /ccc/bbb and forward the requests accordingly. The following figure shows the sample configuration.

    示例1

    Parameter

    Description

    If Match All Conditions

    Regular expression match

    • Match conditions

      The requested path matches the specified regular expression.

    • Requirements

      The regular expression can contain only letters, digits, and the following special characters: . - _ / = ? ~ ^ * $ : ( ) [ ] + |.

    • Examples

      Requested path: /sys/ccc/bbb/aaa

      • Case-sensitive regular expression: The requested path is matched if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.

      • Case-insensitive regular expression: The requested path is matched if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.

    Action

    Rewrite

    • Domain Name: ${host}

    • Path: /${1}/${2}

    • Search: ${query}

    Note

    Set Search to the part follows the question mark (?) in a URL.

    Example: To rewrite URLs to www.example.com/test/test1?x=1, set Search to x=1.

    Forward

    Select a server group from the drop-down list.

    Example 2: Configure the Redirect action

    In this example, a forwarding rule is configured to redirect requests originally destined for sys/ccc/bbb/aaa to /ccc/bbb. The following figure shows the sample configuration.

    示例2

    Parameter

    Description

    If Match All Conditions

    Regular expression match

    • Match conditions

      The requested path matches the specified regular expression.

    • Requirements

      The regular expression can contain only letters, digits, and the following special characters: . - _ / = ? ~ ^ * $ : ( ) [ ] + |.

    • Examples

      Requested path: /sys/ccc/bbb/aaa

      • Case-sensitive regular expression: The requested path is matched if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.

      • Case-insensitive regular expression: The requested path is matched if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.

    Action

    Redirect

    • Protocol: $protocol

    • Domain Name: ${host}

    • Port: ${port}

    • Path: /${1}/${2}

    • Search: ${query}

    • Status Code: 301

FAQ

How can I rewrite the domain only, without modifying the path?

If you need to rewrite the domain of a request to a new domain while keeping the original path and query string, configure your rule as follows:

  • Forwarding condition: Set the Host condition to the original domain (e.g., old.example.com).

  • Forwarding action: Set the action type to Rewrite and configure the following:

    • Domain: The new domain (e.g., new.example.com).

    • Path: ${path} (This preserves the original path).

    • Query: ${query} (This preserves the original query string).

Finally, configure the rule to forward the rewritten request to your target server group.

How do I add a path prefix?

If you need to prepend a prefix, such as a version number, to the original request path (for example, rewriting /users/list to /v2/users/list), configure your rule as follows:

  • Forwarding condition: Set the Path to match the regular expression ^/(.*).

    Explanation: This expression captures the entire path that follows the initial / into a group.

  • Forwarding action: Set the action type to Rewrite, and set the Path to /v2/${1}. Then, configure the rule to forward the request to a server group.

    Explanation: The ${1} is a variable that represents the content captured by the first group (.*) in the condition's regular expression.

After this configuration is applied, a request for /users/list will be rewritten to /v2/users/list before being forwarded to the backend server.

How can I configure a forwarding rule to remove a specific prefix from the request URL path and forward the request based on the subsequent directories?

Solution:

Assume you want ALB to remove /api from the URL of requests destined for www.example.com/api/aaa/bbb/… and forward the requests based on the directories following /api.

In the forwarding rule, set Add Condition to Path, select Regular Expression Matching, and set the path to ^/api/(.*) to match all requests whose URL path starts with /api. Set Action to Rewrite or Redirect, and set the action Path to /${1} to use the part following /api in the original URL path.

Sample configurations are as follows:

  • Rewrite

    image

  • Redirect

    重定向01

References

For more information about how to configure other forwarding rules for an ALB listener, see Configure listener forwarding rules.