This topic describes how to configure domain name-based and path-based forwarding conditions for Application Load Balancer (ALB) listeners. This topic also describes how to configure paths 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 Create a forwarding rule section of the Manage forwarding rules for a listener topic.
Match type | Description |
Exact match and wildcard match |
|
Regular expression match |
|
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 Create a forwarding rule section of the " Manage forwarding rules for a listener" topic.
Match type | Description |
Exact match and wildcard match |
|
Regular expression match |
|
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 Create a forwarding rule section of the Manage forwarding rules for a listener topic.
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
URL matching: The client sends a request. 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 the content 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.
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
andbbb
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 byccc
.${2}
is replaced bybbb
.
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. The following examples show how to configure forwarding rules.
Example 1: Configure the Rewrite or Forward action
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}
Forward
Select a server group from the drop-down list.
Example 2: Configure the Redirect action
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
References
For more information about how to configure other forwarding rules for an ALB listener, see Configure forwarding rules for an ALB listener.