Updated on 2025-07-25 GMT+08:00

Action

Introduction

You can add advanced forwarding policies to HTTP or HTTPS listeners to forward requests to different backend server groups based on a wide range of forwarding rules and actions.

Action Types

Advanced forwarding policies support the following actions: forward to a backend server group, redirect to another listener, redirect to another URL, and return a specific response body.

The following additional actions are supported:

  • Forward to backend server group: rewrite, write header, remove header, and limit request
  • Return a specific response body: limit request.
Table 1 Actions of an advanced forwarding policy

Action

Description

Forward to a backend server group

Requests are forwarded to the specified backend server group.

NOTE:

If Action is set to Forward to a backend server group, you can also select from one of the following actions: Rewrite, Write header, Remove header, and Limit request.

For details, see Table 2.

Redirect to another listener

Requests are redirected to another listener, which then routes the requests to its associated backend server group.

NOTE:

If you select Redirect to another listener, the configurations for the HTTP listener will not be applied, but access control configured for the listener will still be applied.

For example, if you configure a redirect for an HTTP listener, HTTP requests to access a web page will be redirected to the HTTPS listener you select and handled by the backend servers associated with the HTTPS listener. As a result, the clients access the web page over HTTPS.

Redirect to another URL

Requests are redirected to the configured URL.

When clients access website A, the load balancer returns 302 or any other 3xx status code and automatically redirects the clients to website B. You can customize the redirection URL that will be returned to the clients.

Configure at least one of the following components:
  • Protocol: ${protocol}, HTTP, or HTTPS ${protocol}: retains the protocol of the request.
  • Domain Name: A domain name consists of at least two labels separated by periods (.). Each label can contain only letters, digits, hyphens (-), and dots (.), must start with a letter, digit, or asterisk (*), and cannot end with a hyphen (-). ${host}: retains the domain name of the request.
  • Port: ranges from 1 to 65535. ${port}: retains the port number of the request.
  • Path: A path can contain letters, digits, and special characters: _-';@^- %#&$.*+?,=!:|\/()[]{} and must start with a slash (/). ${path}: retains the path of the request.
    NOTE:

    If you select regular expression match, the request path will be overwritten by the variables that match the regular expressions.

  • Query String: A query string can contain only letters, digits, and the following special characters: !$'()*+,./:;=?@&^-_', and & can only be used as a separator.
  • HTTP status code: 301, 302, 303, 307, or 308
Example
URL for redirection: http://www.example1.com/index.html?locale=en-us#videos
Protocol: HTTP
Domain name: www.example1.com
Port: 8081
Path: /index.html
Query string: locale=en-us
HTTP status code: 301

Rewrite

Rewrites the request URL before forwarding requests to the specified backend server group.

Configure the following parameters:
  • Domain Name: A domain name consists of at least two labels separated by periods (.). Each label can contain only letters, digits, hyphens (-), and dots (.), must start with a letter, digit, or asterisk (*), and cannot end with a hyphen (-). ${host}: retains the domain name of the request.
  • Path: A path can contain letters, digits, and special characters: _-';@^- %#&$.*+?,=!:|\/()[]{} and must start with a slash (/). ${path}: retains the path of the request.
    NOTE:

    If you select regular expression match, the requested path will be overwritten by the variables that match the regular expressions. For details, see .

  • Query String: A query string can contain only letters, digits, and the following special characters: !$'()*+,./:;=?@&^-_', and & can only be used as a separator.
NOTE:

The domain name, path, and query string cannot be left blank or made default.

Return a specific response body

Load balancers return a fixed response to the clients.

You can custom the status code and response body that load balancers directly return to the clients without the need to route the requests to backend servers.

Configure the following parameters:
  • HTTP status code: By default, 2xx, 4xx, and 5xx status codes are supported.
  • Content-Type: text/plain, text/css, text/html, application/javascript, or application/json
  • Message Body: This parameter is optional.

Example

text/plain

Sorry, the language is not supported.

text/css

<head><style type="text/css">div {background-color:red}#div {font-size:15px;color:red}</style></head>

text/html

<form action="/" method="post" enctype="multipart/form-data"><input type="text" name="description" value="some text"><input type="file" name="myFile"><button type="submit">Submit</button></form>

application/javascript

String.prototype.trim = function() {var reExtraSpace = /^\s*(.*?)\s+$/;return this.replace(reExtraSpace, "$1")}

application/json

{ "publicip": { "type": "5_bgp","ip_version": 4},"bandwidth": {"name": "bandwidth123","size": 10,"share_type": "PER"}}
NOTE:

Ensure that the response body does not contain carriage return characters. Otherwise, it cannot be saved.

Table 2 Actions (optional)

Action

Description

Rewrite

Rewrites the request URL before forwarding requests to the specified backend server group.

Configure the following parameters:
  • Domain Name: A domain name consists of at least two labels separated by periods (.). Each label can contain only letters, digits, hyphens (-), and dots (.), must start with a letter, digit, or asterisk (*), and cannot end with a hyphen (-). ${host}: retains the domain name of the request.
  • Path: A path can contain letters, digits, and special characters: _-';@^- %#&$.*+?,=!:|\/()[]{} and must start with a slash (/). ${path}: retains the path of the request.
    NOTE:

    If you select regular expression match, the requested path will be overwritten by the variables that match the regular expressions.

  • Query String: A query string can contain only letters, digits, and the following special characters: !$'()*+,./:;=?@&^-_', and & can only be used as a separator.
NOTE:

The domain name, path, and query string cannot be left blank or made default.

Write header

Writes the configured header into the request before forwarding it to the specified backend server group.

You can specify the key and value of the header you want to write into the request that matches the forwarding rule. The headers you have configured will overwrite the existing headers. By default, you can configure five headers.

A header consists of a key and one or more values. You need to configure the key and values separately.
  • The key can contain only letters, digits, underscores (_), and hyphens (-).
  • Multiple values can be configured for a key. The value can contain only letters, digits, and special characters: !#$%&'()*+,.\/:;<=>?@[]^-_'{|}~. Asterisks (*) and question marks (?) can be used as wildcard characters.
    • Manually-defined value: Manually specify a header value.

      Each value cannot start or end with a space and can contain only letters, digits, and special characters !#$%&'"()*+,.\\/:;<=>?@[]^-_`{|}~

    • System-defined value: The following options are supported.

      Client port, client IP address, request protocol, load balancer instance ID, listener port, load balancer EIP, and load balancer private IP

    • Reference value: Use the value of a request header.

      The value can contain only letters, digits, underscores (_), and hyphens (-).

For details about how to write a header, see Table 3.

Remove header

Removes the configured headers from the request before forwarding it to the specified backend server group.

You can specify the value of the header you want to remove from the request that matches the forwarding rule. The headers match the ones you have configured will be removed from the requests. By default, you can configure five headers.

The key can contain only letters, digits, underscores (_), and hyphens (-).

Table 3 Writing a header

Request Header

Header Key

Header Value

Written Request Header

header1:aaa

header2:bbb

header3

Manually-defined value

ccc

header1:aaa

header2:bbb

header3:ccc

header3

System-defined value

Client port

header1:aaa

header2:bbb

header3: Client port

header3

Reference value

header1

header1:aaa

header2:bbb

header3:aaa

The value of the following headers cannot be modified:

connection, upgrade, content-length, transfer-encoding, keep-alive, te, host, cookie, remoteip, authority, x-forwarded-host, x-forwarded-for, x-forwarded-for-port, x-forwarded-tls-certificate-id, x-forwarded-tls-protocol, x-forwarded-tls-cipher, x-forwarded-elb-ip, x-forwarded-port, x-forwarded-elb-id, x-forwarded-elb-vip, x-real-ip, x-forwarded-proto, x-nuwa-trace-ne-in, and x-nuwa-trace-ne-out.