Creates multiple forwarding rules.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateRules

The operation that you want to perform.

Set the value to CreateRules.

ListenerId String Yes lsr-bp1bpn0kn908w4nbw****

The listener ID of the SLB instance.

ClientToken String No 5A2CFF0E-5718-45B5-9D4D-70B3FF3898

The client token that is used to ensure the idempotency. You can use the client to generate the value, but you must ensure that it is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length.

DryRun Boolean No true

Specifies whether to precheck the API request. Valid values:

true: only prechecks the API request. If you select this option, the specified endpoint service is not created after the request passes the precheck. The system prechecks the required parameters, request format and service limits. If the request fails the precheck, the corresponding error message is returned. If the request passes the precheck, the DryRunOperation error code is returned.

false (default): checks the request. After the request passes the check, an HTTP_2xx status code is returned and the operation is performed.

Rules Array Yes

The forwarding rules.

Priority Integer No 10

The priority of the rule. Valid values: 1 to 10000. A smaller value specifies a higher priority.

Note The priority of each rule must be unique.
RuleActions Array Yes

The actions of the rule.

FixedResponseConfig Object No

The configuration of the fixed response.

Content String No dssacav

The content of the fixed response. The response cannot exceed 1 KB in size and can contain only ASCII characters.

ContentType String No text/plain

The format of the fixed response.

Valid values: text/plain, text/css, text/html, application/javascript, and application/json.

HttpCode String No 200

The HTTP status code of the response. The code must be an HTTP_2xx, HTTP_4xx or HTTP_5xx numeric string. x can be any number.

ForwardGroupConfig Object No

The configuration of the forwarding action.

ServerGroupTuples Array No

The destination server groups.

ServerGroupId String No sg-xxxxx

The ID of the destination server group.

InsertHeaderConfig Object No

The configuration of the inserted header.

Key String No key

The name of the inserted header. The name must be 1 to 40 characters in length, and can contain letters, digits, underscores (_), and hyphens (-). The name must be different from the value of InsertHeader.

Note Do not use the following headers:

slb-id, slb-ip, x-forwarded-for, x-forwarded-proto, x-forwarded-eip, x-forwarded-port, x-forwarded-client-srcport, connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, and authority. The preceding names are not case-sensitive.

Value String No ClientSrcPort

The value of the inserted header.

If ValueType is set to SystemDefined, valid values are:

  • ClientSrcPort: The header value is the client port.
  • ClientSrcIp: The header value is the IP address of the client.
  • Protocol: The header value is the protocol (HTTP or HTTPS) of the client request.
  • SLBId: The header value is the ID of the ALB instance.
  • SLBPort: The header value is the listener port of the ALB instance.

If you specify the value type as UserDefined: The value must be 1 to 128 characters in length. The value can contain lowercase letters, printable characters whose ASCII value is greater than or equal to 32 and smaller than 127, and wildcards such as asterisks (*) and question marks (?). The value cannot start or end with a space.

If ValueType is set to ReferenceHeader: The value must be 1 to 128 characters in length, and can contain lowercase letters, digits, underscores (_), and hyphens (-).

ValueType String No ClientSrcPort

The type of the header value. Valid values:

  • UserDefined: The value is user-defined.
  • ReferenceHeader: The value is referenced from request headers.
  • SystemDefined: The value is system-defined.
Order Integer Yes 1

The order of the forwarding action. Valid values: 1 to 50000. The actions are performed in ascending order. The value must be specified and unique.

RedirectConfig Object No

The configuration of the redirect action.

Host String No ww.ali.com

The host name of the destination to which requests are directed.

Valid values:

  • The host name must be 3 to 128 characters in length, and can contain lowercase letters, digits, hyphens (-), periods (.), and wildcards such as asterisks (*) and question marks (?).
  • The host name must contain at least one period (.), and cannot start or end with a period (.).
  • The rightmost field can contain only letters and wildcards, and cannot contain digits or hyphens (-).
  • Other fields cannot start or end with a hyphen (-). You can include wildcards such as asterisks (*) and question marks (?) anywhere in a field.

Default value: ${host}. You cannot use this value together with other characters at the same time.

HttpCode String No 301

Redirect method. Valid values: 301, 302, 303, 307, and 308.

Path String No /test

The path of the destination to which requests are directed.

Valid values: The path must be 1 to 128 characters in length, and start with a forward slash (/). The path can contain letters, digits, and the following special characters: $ - _ . + / & ~ @ :. The path cannot contain the following special characters: " % # ; ! ( ) [ ] ^ , ". The path is case-sensitive and can contain wildcards such as asterisks (*) and question marks (?).

Default value: ${path}. You can also reference ${host}, ${protocol}, and ${port}. Each variable can appear only once. You can use the preceding variables at the same time, or use them together with a valid string.

Port String No 10

The port of the destination to which requests are directed.

Valid values: 1 to 63335.

Default value: ${port}. You cannot use this value together with other characters at the same time.

Protocol String No HTTP

The protocol of the destination to which requests are directed.

Valid values: HTTP and HTTPS.

Default value: ${protocol}. You cannot use this value together with other characters at the same time.

Note You can only be redirected to an HTTPS protocol when an HTTPS listener is created.
Query String No quert

The query string to which requests are directed.

Valid values: The query string must be 1 to 128 characters in length, can contain letters and printable characters and cannot contain the following special characters: # [ ] { } \ | < > &.

Default value: ${query}. You can also reference ${host}, ${protocol}, and ${port}. Each variable can appear only once. You can use the preceding variables at the same time, or use them together with a valid string.

RewriteConfig Object No

The configuration of the rewrite action.

Host String No www.al.com

The host name of the destination to which requests are directed.

Valid values:

  • The host name must be 3 to 128 characters in length, and can contain lowercase letters, digits, hyphens (-), periods (.), and wildcards such as asterisks (*) and question marks (?).
  • The host name must contain at least one period (.), and cannot start or end with a period (.).
  • The rightmost field can contain only letters and wildcards, and cannot contain digits or hyphens (-).
  • Other fields cannot start or end with a hyphen (-). You can include wildcards such as asterisks (*) and question marks (?) anywhere in a field.

Default value: ${host}. You cannot use this value together with other characters at the same time.

Path String No /tsdf

The path of the destination to which requests are directed.

Valid values: The path must be 1 to 128 characters in length, and start with a forward slash (/). The path can contain letters, digits, and the following special characters: $ - _ . + / & ~ @ :. The path cannot contain the following special characters: " % # ; ! ( ) [ ] ^ , ". The path is case-sensitive and can contain wildcards such as asterisks (*) and question marks (?).

Default value: ${path}. This value can appear only once. You can use it with a valid string.

Query String No quedsa

The query string to which requests are directed.

Valid values: The query string must be 1 to 128 characters in length, can contain letters and printable characters and cannot contain the following special characters: # [ ] { } \ | < > &.

Default value: ${query}. This value can appear only once. You can use it with a valid string.

Type String Yes ForwardGroup

The action type. Valid values:

  • ForwardGroup: forwards requests to multiple vServer groups.
  • Redirect: redirects requests.
  • FixedResponse: returns a fixed response.
  • Rewrite: rewrites requests.
  • InsertHeader: inserts headers into requests.

Type:

FinalType: A forwarding rule can contain only one FinalType action, which is executed last. This type of action can contain only one ForwardGroup, Redirect or FixedResponse action.

ExtType: A forwarding rule can contain one or more ExtType actions, which are executed before FinalType actions and need to coexist with the FinalType actions. This type of action can contain multiple InsertHeader actions or one Rewrite action.

RuleConditions Array Yes

The conditions of the forwarding rule.

CookieConfig Object No

The configuration of the cookie.

Values Array No

The values of the cookie.

Key String No test

The key of the cookie must be 1 to 100 characters in length, and can contain lowercase letters, printable characters, and wildcards such as asterisks (*) and question marks (?). The key of the cookie cannot contain spaces or the following special characters: # [ ] { } \ | < > &.

Value String No test

The value of the cookie must be 1 to 128 characters in length, and can contain lowercase letters, printable characters, and wildcards such as asterisks (*) and question marks (?). The value of the cookie cannot contain spaces or the following special characters: # [ ] { } \ | < > &.

HeaderConfig Object No

The configuration of the header.

Key String No Port

The key of the header. The header key must be 1 to 40 characters and can contain letters, digits, hyphens (-) and underscores (_). The header key does not support Cookie or Host.

Values Array of String No 5006

The value of the header. The header value must be 1 to 128 characters in length, and can contain lowercase letters, printable characters whose ASCII value is greater than or equal to 32 and smaller than 127, and wildcards such as asterisks (*) and question marks (?). The header value cannot start or end with a space.

HostConfig Object No

The configuration of the host.

Values Array of String No www.test.com

The name of the host.

Valid values:

  • The host name must be 3 to 128 characters in length, and can contain lowercase letters, digits, hyphens (-), periods (.), and wildcards such as asterisks (*) and question marks (?).
  • The host name must contain at least one period (.), and cannot start or end with a period (.).
  • The rightmost field can contain only letters and wildcards, and cannot contain digits or hyphens (-).
  • Other fields cannot start or end with a hyphen (-). You can include wildcards such as asterisks (*) and question marks (?) anywhere in a field.
MethodConfig Object No

The configuration of the request method.

Values Array of String No PUT

The request method.

Valid values: HEAD, GET, POST, OPTIONS, PUT, PATCH, and DELETE.

PathConfig Object No

The configuration of the forwarding path.

Values Array of String No /test

The forwarding path.

Valid values: The path must be 1 to 128 characters in length, and start with a forward slash (/). The path can contain letters, digits, and the following special characters: $ - _ . + / & ~ @ :. The path cannot contain the following special characters: " % # ; ! ( ) [ ] ^ , ". The path is case-sensitive and can contain wildcards such as asterisks (*) and question marks (?).

QueryStringConfig Object No

The configuration of query string parameters.

Values Array No

The parameters of the query string.

Key String No test

They key of the query string.

The key of the query string must be 1 to 100 characters in length, and can contain lowercase letters, printable characters, and wildcards such as asterisks (*) and question marks (?). The key of the query string cannot contain spaces or the following special characters: # [ ] { } \ | < > &.

Value String No test

The value of the query string.

The value of the query string must be 1 to 128 characters in length, and can contain lowercase letters, printable characters, and wildcards such as asterisks (*) and question marks (?). The value of the query string cannot contain spaces or the following special characters: # [ ] { } \ | < > &.

ResponseHeaderConfig Object No

The configuration of header parameters.

Key String No Port

The key of the header. The header key must be 1 to 40 characters and can contain letters, digits, hyphens (-) and underscores (_). The header key does not support Cookie or Host.

Values Array of String No 5006

The value of the header. The header value must be 1 to 128 characters in length, and can contain lowercase letters, printable characters whose ASCII value is greater than or equal to 32 and smaller than 127, and wildcards such as asterisks (*) and question marks (?). The header value cannot start or end with a space.

Type String Yes Host

The type of the forwarding rule. Valid values:

  • Host: Requests are forwarded based on the host.
  • Path: Requests are forwarded based on the path.
  • Header: Requests are forwarded based on the HTTP header.
  • QueryString: Requests are forwarded based on the query string.
  • Method: Request are forwarded based on the request method.
  • Cookie: Requests are forwarded based on the cookie.
RuleName String No rule-doc****

The name of the forwarding rule. The name must be 2 to 128 characters in length, and must start with a letter. It can contain digits, periods (.), underscores (_), and hyphens (-).

Response parameters

Parameter Type Example Description
JobId String 72dcd26b-f12d-4c27-b3af-18f6aed5****

The ID of the asynchronous task.

RequestId String 365F4154-92F6-4AE4-92F8-7FF34B540710

The ID of the request.

RuleIds Array of RuleId

The forwarding rules.

RuleId String rule-doc****

The ID of forwarding rules.

Examples

Sample requests

http(s)://[Endpoint]/?Action=CreateRules
&ListenerId=lsr-bp1bpn0kn908w4nbw****
&ClientToken=5A2CFF0E-5718-45B5-9D4D-70B3FF3898
&DryRun=true
&Rules=[{"Priority":10,"RuleActions":[{"FixedResponseConfig":{"Content":"dssacav","ContentType":"text/plain","HttpCode":"200"},"ForwardGroupConfig":{"ServerGroupTuples":[{"ServerGroupId":"sg-xxxxx"}]},"InsertHeaderConfig":{"Key":"key","Value":"ClientSrcPort","ValueType":"ClientSrcPort"},"Order":1,"RedirectConfig":{"Host":"ww.ali.com","HttpCode":"301","Path":"/test","Port":"10","Protocol":"HTTP","Query":"quert"},"RewriteConfig":{"Host":"www.al.com","Path":"/tsdf","Query":"quedsa"},"Type":"ForwardGroup"}],"RuleConditions":[{"CookieConfig":{"Values":[{"Key":"test","Value":"test"}]},"HeaderConfig":{"Key":"Port","Values":["5006"]},"HostConfig":{"Values":["www.test.com"]},"MethodConfig":{"Values":["PUT"]},"PathConfig":{"Values":["/test"]},"QueryStringConfig":{"Values":[{"Key":"test","Value":"test"}]},"ResponseHeaderConfig":{"Key":"Port","Values":["5006"]},"Type":"Host"}],"RuleName":"rule-doc****"}]
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateRulesResponse>
    <JobId>72dcd26b-f12d-4c27-b3af-18f6aed5****</JobId>
    <RequestId>365F4154-92F6-4AE4-92F8-7FF34B540710</RequestId>
    <RuleIds>
        <RuleId>rule-doc****</RuleId>
    </RuleIds>
</CreateRulesResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "JobId" : "72dcd26b-f12d-4c27-b3af-18f6aed5****",
  "RequestId" : "365F4154-92F6-4AE4-92F8-7FF34B540710",
  "RuleIds" : {
    "RuleId" : "rule-doc****"
  }
}

Error codes

HttpCode Error code Error message Description
400 IncorrectStatus.Listener The status of %s [%s] is incorrect. The error message returned because the status of the specified resource is invalid.
400 OperationDenied.IpGroupCanNotUsedForMirrorAction The operation is not allowed because of %s. The error message returned because the operation is not allowed because of %s.
400 OperationDenied.SameGroupForForwardAndMirrorAction The operation is not allowed because of %s. The error message returned because the operation is not allowed because of %s.
400 OperationDenied.GRPCServerGroup The operation is not allowed because of %s. The error message returned because the operation is not allowed because of %s.
400 Conflict.Priority There is already %s having the same configuration with %s. The error message returned because an existing %s parameter has the same configuration.
400 ResourceQuotaExceeded.LoadBalancerRulesNum The quota of %s is exceeded for resource %s, usage %s/%s. The error message returned because the quota %s of the specified resource %s has exhausted. The current usage is %s.
400 ResourceQuotaExceeded.ServerGroupAttachedNum The quota of %s is exceeded for resource %s, usage %s/%s. The error message returned because the quota %s of the specified resource %s has exhausted. The current usage is %s.
400 ResourceQuotaExceeded.LoadBalancerServersNum The quota of %s is exceeded for resource %s, usage %s/%s. The error message returned because the quota %s of the specified resource %s has exhausted. The current usage is %s.
400 ResourceQuotaExceeded.ServerAddedNum The quota of %s is exceeded for resource %s, usage %s/%s. The error message returned because the quota %s of the specified resource %s has exhausted. The current usage is %s.
400 QuotaExceeded.RuleWildcardsNum The quota of %s is exceeded, usage %s/%s. The error message returned because the usage %s has exceeded the quota %s.
400 QuotaExceeded.RuleMatchEvaluationsNum The quota of %s is exceeded, usage %s/%s. The error message returned because the usage %s has exceeded the quota %s.
400 QuotaExceeded.RuleActionsNum The quota of %s is exceeded, usage %s/%s. The error message returned because the usage %s has exceeded the quota %s.
400 Mismatch.VpcId The %s is mismatched for %s and %s. The error message returned because %s and %s does not correspond to each other.
400 Mismatch.Protocol The %s is mismatched for %s and %s. The error message returned because %s and %s does not correspond to each other.
400 OperationDenied.RewriteMissingForwardGroup The operation is not allowed because of RewriteMissingForwardGroup. The error message returned because the operation is not allowed because of RewriteMissingForwardGroup.
404 ResourceNotFound.Listener The specified resource %s is not found. The error message returned because the specified resource %s does not exist.
404 ResourceNotFound.ServerGroup The specified resource %s is not found. The error message returned because the specified resource %s does not exist.

For a list of error codes, visit the API Error Center.