The listeners of Application Load Balancer (ALB) support domain name-based forwarding rules and URL-based forwarding rules. This topic describes how to configure domain name-based forwarding rules and URL-based forwarding rules. This topic also provides instructions on how to configure rewrite and redirect settings in forwarding rules.

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 add a forwarding rule, see Create a forwarding rule.
Match typeDescription
Exact match and wildcard match
  • Match conditions
    • Exact match: matches only if the requested domain name is exactly the same as the specified domain name.
    • Wildcard match: matches 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 wildcard characters, such as asterisks (*) and question marks (? ).

  • Examples
    Requested domain name: www.example.com
    • Exact match: matches only if www.example.com is specified in the forwarding rule.
    • Wildcard match: matches if *.example.com or www.example.* is specified in the forwarding rule.
Regular expression match
  • Match conditions

    Matches the specified regular expression.

  • Requirements

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

  • Examples

    Requested domain name: www.Example.com

    Case-insensitive regular expression: matches 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 add a forwarding rule, see Create a forwarding rule.
Match typeDescription
Exact match and wildcard match
  • Match conditions
    • Exact match: matches if the requested URL is exactly the same as the specified URL.
    • Wildcard match: matches the wildcard pattern of the specified URL.
  • Requirements

    The URL 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 wildcards.

  • Examples
    Requested URL: /example/text
    • Exact match: matches only if /example/text is specified in the forwarding rule.
    • Wildcard match: matches if /example/* is specified in the forwarding rule.
    Note The URL match rules of ALB are different from those of NGINX. ALB does not support the longest prefix match rule.

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

Regular expression match
  • Match conditions

    Matches the specified regular expression.

  • Requirements

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

  • Examples

    Requested URL: /sys/aaa/HOST

    • Case-sensitive regular expression: matches if ^/sys/(.*)/HOST$ is specified in the forwarding rule.
    • Case-insensitive regular expression: matches 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 add a forwarding rule, see Create a forwarding rule.
Note For more information about how to configure a regular expression as the match condition in a URL-based forwarding rule, see the URL-based forwarding rules section in 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 and 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 them 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.
    Step numberStepExample
    1Configure the forwarding conditions and forwarding actions for a forwarding rule.
    • The regular expression for requested URLs: /sys/(.*)/(.*)/aaa
    • The regular expression for the URL that replaces the original URL: /${1}/${2}
    2A client request matches a regular expression that is specified in a forwarding rule.
    • Requested URL: /sys/ccc/bbb/aaa
    • Matched regular expression: /sys/(.*)/(.*)/aaa
    3Overwrite the original URL with the variables that match the regular expressions.Variables ${1} and ${2} that match the (.*) in the regular expression are overwritten.
    • ${1} is overwritten by ccc.
    • ${2} is overwritten by bbb.
    4Splice the strings that overwrote the variables to form the new URL.The URL received by the backend server is /ccc/bbb.
  • Examples

    You can create forwarding rules in the ALB console. The following examples show how to configure forwarding rules.

    Example 1: The forwarding action is Rewrite or ForwardExample 1
    ParameterDescription
    If (Matching All Conditions)Regular expression match
    • Match conditions

      Matches the specified regular expression.

    • Requirements

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

    • Examples

      Requested URL: /sys/ccc/bbb/aaa

      • Case-sensitive regular expression: matches if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.
      • Case-insensitive regular expression: matches if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.
    ThenRewrite
    • Domain Name: ${host}
    • Path: /${1}/${2}
    • Query: ${query}
    ForwardSelect a server group from the drop-down list.
    Example 2: The forwarding action is RedirectExample 2
    ParameterDescription
    If (Matching All Conditions)Regular expression match
    • Match conditions

      Matches the specified regular expression.

    • Requirements

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

    • Examples

      Requested URL: /sys/ccc/bbb/aaa

      • Case-sensitive regular expression: matches if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.
      • Case-insensitive regular expression: matches if /sys/(.*)/(.*)/aaa is specified in the forwarding rule.
    ThenRedirect
    • Protocol: $protocol
    • Domain Name: ${host}
    • Port: ${port}
    • Path: /${1}/${2}
    • Query: ${query}
    • Status Code: 301