# Forwarding Rules

## Add Content Forwarding Rule

Under the HTTP/HTTPS protocol, VServer supports domain name or access path matching according to the forwarding policy, which can forward matching requests to specific hosts in the back end, and manage the back-end service nodes in a fine-grained manner. By default, a policy called **Default Rule** will exist. This policy will take effect when all requests are not matched successfully and will be forwarded according to the usual forwarding rules.

> Only HTTP and HTTPS protocol listeners support content forwarding policy.

### Procedure

Go to the **VServer Management Page**, click **Content Forwarding** to manage content forwarding rules.

1. Click **Add Rule** to pop up the Add Rule dialog box.

<!-- image-todo -->

2. **Forwarding Rules**. Forwarding rules are divided into "Domain Name Forwarding" and "Path Forwarding", both of which can use regular expressions that comply with the PCRE rules. Other filling restrictions are as follows:

|   Limitation   |   Domain Name Forwarding   | Path Forwarding |
| :-------------: |:---------:|:--------: |
| Length Limitation | The length of the forwarding domain name should not exceed 255 characters, and the single-level length should not exceed 63 characters. Supports regular expressions and wildcard domain names. | 1-255 characters | 
| Supported Characters | <br>1. Regular expressions support Chinese, letters, numbers and special characters. - ? = ~ _ - + ^ * ! $ : & \| ( ) [ ] (":" can only be used in the form of domain name plus port, used in non-80 port HTTP and non-443 port HTTPS scenarios.) <br>2. Wildcard domain names support Chinese, letters, numbers and special characters. : * _ - | Supports Chinese, letters, numbers and special characters. - _ / = ? ^ * $ ! : ( ) [ ] + \| | 
| Others | <br>1._ cannot appear at the beginning or end. <br>2. For wildcard domain names, currently only support * . or . at the beginning or . * or . at the end, and only allow * to appear once in a single domain name. | \ |

**Examples of Domain Name Forwarding**:
- Regular expression: www.[123].demo.com can match domain names like www.1.demo.com, www.2.demo.com, www.3.demo.com, etc.
- Wildcard domain: *.demo.com or .demo.com can match all domain names ending with demo.com, www.demo.* or www.demo. can match all domain names starting with www.demo.


**Path Forwarding Examples**:

- Regular expression: /path/img/.*.jpg can match all files ending with jpg under /path/img/ path, for example /path/img/demo.jpg, /path/img/1/demo.jpg, etc.

3. **Optional Nodes**. Each rule needs to be associated with an existing service node, select the node to associate.

4. Click **OK** to complete the addition of forwarding rules.

<!-- image-todo -->

## Delete Content Forwarding Rule

> The default rule does not support deletion.

### Procedure

Go to the **VServer Management Page**, click **Content Forwarding** to manage content forwarding rules.

#### Delete a Single Forwarding Rule

1. Select the rule to delete, click **Delete**.

<!-- image-todo -->

2. A pop-up window will display the selected forwarding rule information, confirm whether it is the rule to be deleted.

3. Click **OK** to delete the forwarding rule.

#### Batch Delete Forwarding Rules

1. Select the **check box** on the left side of the rules to be deleted, click **Delete Rule** at the top.

<!-- image-todo -->

2. A pop-up window will display the selected forwarding rule information, confirm whether they are the rules to be deleted.

3. Click **OK** to complete the batch deletion of forwarding rules.

## Manage Content Forwarding Rule

### Procedure

Go to the **VServer Management Page**, click **Content Forwarding** to manage content forwarding rules.

> The default rule cannot be edited. After adding a rule, you can edit the nodes associated with the current rule.

1. Select the forwarding rule to be edited, click **Manage**.

2. The management dialog box pops up.

<!-- image-todo -->

* **Optional Nodes**. Resources in the current service node resource pool that are not associated with this rule.
* **Forwarding Nodes**. Resources in the current service node resource pool that are associated with this rule.

### Add Service Node Associated with Rule

1. Select the **check box** on the left side of the resources in the optional node list, move to the forwarding node list.

2. Click **OK** to complete node association operation.

### Cancel Existing Associated Service Node

1. Select the **check box** on the left side of the resources in the forwarding node list, move to the optional node list.

2. Click **OK** to complete un-associating node operation.