Create Redirection V2
This API is used to create redirection for website acceleration service.
Request
Request-Line
POST /cdn/v1.1/services/{serviceId}/redirections HTTP/1.1
Request Parameters
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| serviceId | Integer | Mandatory | service id. |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| policyName | String | Mandatory | Policy name for redirection. |
| matches | Array | Mandatory | Matching configuration that determines which requests the rule applies to. See Matches for details. |
| redirectDestination | String | Mandatory | Send an HTTP redirect if this policy matches. |
| httpCode | Integer | Mandatory | HTTP response code to use if sending an HTTP redirect. Could be "301/302". |
| priority | Integer | Mandatory | Priority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero. |
| enabled | Boolean | Optional | Flag defining if policy is active or no. Default is true. |
Object: Matches
| Parameter | Type | Required | Description |
|---|---|---|---|
| Array | Mandatory | See Match for details. |
Object: Match
| Parameter | Type | Required | Description |
|---|---|---|---|
| field | String | Mandatory | Which part of the request to match. Supported values: • req.path - Request path (excluding query string).• req.query - Request query parameters.• req.method - HTTP method (GET, POST, etc.).• client.ip - Client IP address.• req.host - Request host.• req.header.user-agent - User-Agent header.• req.header.cookie - Cookie header.• req.header.origin - Origin header.• req.header.via - Via header. |
| operator | String | Mandatory | Defines how to match the field. Supported values: • startswith - Succeeds if the what matches one of the prefixes listed in patterns.• not_startswith - Matches if field value does not starts with any of the specified prefixes.• istartswith - Case-independent version of startswith.• not_istartwith - Matches if the field value does not starts with any of the specified prefixes, ignoring letter case differences.• regex - Succeeds if what matches one of the regexes listed in patterns.• equals - Succeeds if the what matches one of the strings listed in patterns.• not_equals - Succeeds if the field value does not exactly match any of the specified strings.• iequals - Case-independent version of equals.• not_iequals - Succeeds if the field value does not exactly match any of the specified strings,ignoring letter case differences.• endswith - Succeeds if the what ends with one of the strings listed in patterns. Useful e.g. to match file extensions like ".mp4".• not_endswith - Succeeds if the what does not ends with one of the strings listed in patterns.• iendswith - Case-independent version of endswith.• not_iendswith - Succeeds if the what does not ends with one of the strings listed in patterns,ignoring letter case differences.• subnet - Succeeds if the what belongs to one of subnets, specified in patterns, like "1.222.94.98/32".• not_subnet - Succeeds if the what does not belongs to one of subnets.Note: subnet operator is applicable only to the client.ip match option. |
| values | String[] | Mandatory | List of values matching the URL path string. |
Response
Reponse Body
| Parameter | Type | Description |
|---|---|---|
| policyName | String | Policy name for redirection. |
| matches | Array | Matching configuration that determines which requests the rule applies to. See Matches for details. |
| redirectDestination | String | Send an HTTP redirect if this policy matches. |
| httpCode | Integer | HTTP response code to use if sending an HTTP redirect. Could be "301/302". |
| priority | Integer | Priority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero. |
| enabled | Boolean | Flag defining if policy is active or no. Default is true. |
Status Codes, Error Codes and Error Messages
| Status Code | Error Code | Error Message |
|---|---|---|
| 400 | Request.BadRequest | Bad request. |
| 400 | InvalidCustomer.IdEmpty | Customer id can be empty or invalid. |
| 400 | InvalidService.IdIncorrect | Service id is empty or invalid. |
| 400 | ServiceId.IdPermission | ServiceId can not be found or unknown. |
| 400 | InvalidRedirection.PolicyName | Policy name is required. |
| 400 | InvalidRedirection.MatchURLIncorrect | The matchUrlPath can not be empty. |
| 400 | InvalidRedirection.Operator | Operator must be one of the following: prefix,regex,equals or suffix. |
| 400 | InvalidRedirection.MatchUrlPathPatternsIncorrect | The MatchUrlPath patterns could not be empty. |
| 400 | InvalidRedirection.URLEmpty | Policy redirection URL is empty. |
| 400 | InvalidRedirection.HttpCodeEmpty | Policy redirection http code is empty. |
| 400 | InvalidRedirection.HttpCode | Policy redirection http code type is 301 or 302. |
| 400 | InvalidRedirection.Priority | Patterns cannot be empty or invalid. |
| 400 | InvalidPolicy.MatchesIncorrect | The matches can not be empty or incorrect. |
| 400 | InvalidPolicy.MatchFieldIncorrect | The match field can not be empty or use the specified value. |
| 400 | InvalidPolicy.MatchOperatorIncorrect | The match operator required or use the specified value. |
| 400 | InvalidPolicy.MatchValuesIncorrect | The match values required or can not be empty. |
| 400 | InvalidPolicy.MatchValueIncorrect | All match values must not be empty. |
Examples
Create Redirection V2
Request
POST /cdn/v1.1/services/226401/redirections HTTP/1.1
{
"policyName":"redo",
"matches":[
{
"field":"req.path",
"operator":"startswith",
"values":["/css/","/images/abc/"]
},
{
"field":"req.host",
"operator":"iequals",
"values":["expamle.com"]
},
{
"field":"req.method",
"operator":"equals",
"values":["get"]
}
],
"priority":1,
"redirectDestination":"www.domain333.com",
"httpCode":302,
"enabled":true
}
Successful Response Body
{
"policyId": 262286,
"policyName": "redo",
"redirectDestination": "www.domain333.com",
"httpCode": 302,
"matches": [
{
"field": "req.path",
"operator": "startswith",
"values": [
"/css/",
"/images/abc/"
]
},
{
"field": "req.host",
"operator": "iequals",
"values": [
"expamle.com"
]
},
{
"field": "req.method",
"operator": "equals",
"values": [
"get"
]
},
{
"field": "req.method",
"operator": "startswith",
"values": [
"192.0.2.100"
]
}
],
"priority": 1,
"enabled": true
}