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
Match type | Description |
---|---|
Exact match and wildcard match |
|
Regular expression match |
|
URL-based forwarding rules
Match type | Description |
---|---|
Exact match and wildcard match |
|
Regular expression match |
|
Advanced URL-based forwarding rule settings for rewrites and redirects
- 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.
- You can specify one or more regular expressions as the match conditions in a rewrite or redirect rule and use parentheses
- Procedure
- URL matching: The client sends a request and the request matches a regular expression that is specified in a forwarding rule.
- 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. - Splicing: splices the strings that overwrote the variables
${1}
,${2}
, and${3}
to form the new URL.
Step number Step Example 1 Configure 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}
2 A client request matches a regular expression that is specified in a forwarding rule. - Requested URL:
/sys/ccc/bbb/aaa
- Matched regular expression:
/sys/(.*)/(.*)/aaa
3 Overwrite 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 byccc
.${2}
is overwritten bybbb
.
4 Splice 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 ForwardParameter Description 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.
- Case-sensitive regular expression: matches if
Then Rewrite - Domain Name:
${host}
- Path:
/${1}/${2}
- Query:
${query}
Forward Select a server group from the drop-down list. Example 2: The forwarding action is RedirectParameter Description 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.
- Case-sensitive regular expression: matches if
Then Redirect - Protocol:
$protocol
- Domain Name:
${host}
- Port:
${port}
- Path:
/${1}/${2}
- Query:
${query}
- Status Code:
301
- Match conditions