文档首页/ 内容分发网络 CDN/ API参考/ API/ 域名配置/ 查询规则引擎列表 - ListRuleDetails
更新时间:2026-07-20 GMT+08:00
分享

查询规则引擎列表 - ListRuleDetails

功能介绍

查询规则引擎列表。

调用方法

请参见如何调用API

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,需具备如下身份策略权限。

    授权项

    访问级别

    资源类型(*为必须)

    条件键

    别名

    依赖的授权项

    cdn:configuration:queryRules

    Read

    domain *

    • g:ResourceTag/<tag-key>

    • g:EnterpriseProjectId

    -

    -

URI

GET /v1.0/cdn/configuration/domains/{domain_name}/rules

表1 路径参数

参数

是否必选

参数类型

描述

domain_name

String

参数解释:

加速域名

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

请求参数

响应参数

状态码:200

表2 响应Body参数

参数

参数类型

描述

rules

Array of RuleResponse objects

规则列表

表3 RuleResponse

参数

参数类型

描述

rule_id

String

规则id

name

String

规则名称

status

String

规则状态,on:开启,off:关闭。

priority

Integer

此条规则的优先级,数值越大,优先级越高。

conditions

Conditions object

参数解释:

触发当前规则的条件

actions

Array of Actions objects

满足规则条件后执行的动作列表

表4 Conditions

参数

参数类型

描述

match

Match object

参数解释:

规则匹配条件

表5 Match

参数

参数类型

描述

logic

String

参数解释:

逻辑运算符

取值范围:

  • and: 与关系

  • or: 或关系

criteria

Array of Criteria objects

参数解释:

匹配条件列表

表6 Criteria

参数

参数类型

描述

match_target_type

String

参数解释:

匹配目标类型

取值范围:

  • scheme: 客户端请求使用的协议类型

  • method: 客户端请求IP使用的请求方法

  • path: 客户端请求URL路径

  • arg: 客户端请求URL中的查询参数

  • extension: 客户端请求IP内容的文件后缀

  • filename: 客户端请求IP内容的文件名称

  • header: HTTP请求头部

  • clientip: 客户端请求IP的客户端IP

  • clientip_version: 客户端请求IP的客户端IP版本

  • ua: 客户端请求IP头中的User-Agent

  • ngx_variable: Nginx变量

match_target_name

String

参数解释:

匹配目标名称

取值范围:

  • 当匹配目标类型为scheme、method、path、extension、filename、ua时,该值为空

  • 当匹配目标类型为arg时表示查询参数名,长度1-100,由数字,大小写字母,中划线和下划线组成,只能以字母开头

  • 当匹配目标类型为header时表示请求头的名称,长度1-100,由数字,大小写字母,中划线和下划线组成,只能以字母开头

  • 当匹配目标类型为clientip时表示ip来源,取值:connect:建联IP;xff:x-forwarded-for头

  • 当匹配目标类型为clientip_version时表示ip版本来源,取值:connect:建联IP;xff:x-forwarded-for头

  • 当匹配目标类型为ngx_variable时表示Nginx变量名,仅支持$protocol、$arg_、$http_、$scheme、$uri、$ssl_protocol、$ssl_server_name、$remote_addr、$http2、$request_method、$sent_http_

match_type

String

参数解释:

匹配算法

取值范围:

contains:包含匹配,匹配到match_pattern任意一个条件即匹配成功

match_pattern

Array of strings

参数解释:

匹配内容

取值范围:

  • 当匹配目标类型为scheme时,取值:HTTP,HTTPS

  • 当匹配目标类型为method时,取值:GET,PUT,POST,DELETE,HEAD,OPTIONS,PATCH,TRACE,CONNECT

  • 当匹配目标类型为clientip_version时,取值:IPv4,IPv6

  • 当匹配目标类型为path和ua时,支持配置通配符“*”

negate

Boolean

参数解释:

是否取反,与match_type配合使用。例:negate配置为true,match_type配置为contains,则实际业务逻辑将转换为not_contains

取值范围:

  • true: 取反

  • false: 不取反

case_sensitive

Boolean

参数解释:

是否区分大小写

取值范围:

  • true: 区分大小写

  • false: 不区分大小写

logic

String

参数解释:

嵌套条件逻辑运算符

取值范围:

  • and: 与关系

  • or: 或关系

criteria

Array of Criteria objects

参数解释:

嵌套条件列表

表7 Actions

参数

参数类型

描述

flexible_origin

Array of flexibleOriginsEngine objects

参数解释:

高级回源,实现根据不同的资源类型或路径回源到不同源站

origin_request_header

Array of OriginRequestHeader objects

参数解释:

CDN节点回源时,改写用户回源请求URL的HTTP头部信息

http_response_header

Array of HttpResponseHeader objects

参数解释:

配置节点响应给客户端的头部信息,配置响应消息后,用户请求加速域名下的资源时,CDN返回给用户的消息中将包含该域名配置的响应头信息

access_control

AccessControl object

参数解释:

访问控制

request_limit_rule

RequestLimitRulesEngine object

参数解释:

请求限速,将用户请求速度限制在指定范围内,一定程度上减少突发高带宽风险,节省成本

origin_request_url_rewrite

OriginRequestUrlRewriteEngine object

参数解释:

改写回源URL

cache_rule

CacheRulesEngine object

参数解释:

通过不同参数控制源站资源在CDN节点的缓存时长

request_url_rewrite

RequestUrlRewriteEngine object

参数解释:

访问URL重写,当用户请求URL与CDN节点缓存资源的URL不一致时,可以通过访问URL重写功能重定向到目标URL

browser_cache_rule

BrowserCacheRulesEngine object

参数解释:

浏览器缓存过期时间,当终端用户请求资源时,如果浏览器有缓存,直接返回给用户

error_code_cache

Array of ErrorCodeCacheEngine objects

参数解释:

将源站返回的错误状态码缓存到CDN节点,用户再次请求时由CDN直接响应给用户错误状态码

表8 flexibleOriginsEngine

参数

参数类型

描述

sources_type

String

参数解释:

源站类型

取值范围:

  • ipaddr: 源站IP

  • domain: 源站域名

  • obs_bucket: OBS桶域名

  • third_bucket: 第三方桶域名

ip_or_domain

String

参数解释:

源站IP或者域名

取值范围:

不涉及

obs_bucket_type

String

参数解释:

OBS桶类型

取值范围:

  • private: 私有桶

  • public: 公有桶

bucket_access_key

String

参数解释:

第三方对象存储访问密钥

取值范围:

不涉及

bucket_secret_key

String

参数解释:

第三方对象存储密钥

取值范围:

不涉及

bucket_region

String

参数解释:

第三方对象存储区域

取值范围:

不涉及

bucket_name

String

参数解释:

第三方对象存储名称

取值范围:

不涉及

host_name

String

参数解释:

回源HOST

取值范围:

不涉及

origin_protocol

String

参数解释:

指定CDN回源时的请求协议

取值范围:

  • follow: 协议跟随

  • http: http协议

  • https: https协议

http_port

Integer

参数解释:

HTTP端口

取值范围:

1-65535

https_port

Integer

参数解释:

HTTPS端口

取值范围:

1-65535

priority

Integer

参数解释:

优先级,值越大优先级越高

取值范围:

1-100

weight

Integer

参数解释:

权重,值越大回源到该源站的次数越多。多个优先级相同的源站,由权重决定回源到各个源站的比例

取值范围:

1-100

表9 OriginRequestHeader

参数

参数类型

描述

name

String

参数解释:

设置回源请求头参数

取值范围:

  • 1-100个字符

  • 由数字,大小写字母,中划线组成

  • 只能以字母开头

value

String

参数解释:

设置回源请求头参数的值

取值范围:

  • 1-1000个字符

  • 由数字0 - 9、字符a - z、A - Z,及特殊符“.”、“-”、“_”、“*”、“#”、“!”、“&”、“+”、“|”、“^”、“~”、“'”、“"”、“/”、“:”、“;”、“,”、“=”、“@”、“?”、“<”、“>”组成

  • 当为删除动作时,可不填

  • 不支持中文

  • 不支持变量配置,如:$client_ip,$remote_port等

action

String

参数解释:

回源请求头设置类型

取值范围:

  • delete: 删除

  • set: 设置

表10 HttpResponseHeader

参数

参数类型

描述

name

String

参数解释:

设置HTTP响应头参数

取值范围:

  • 1-100个字符

  • 由数字,大小写字母,中划线组成,只能以字母开头

value

String

参数解释:

设置HTTP响应头参数的值

取值范围:

  • 1-1000个字符

  • 支持字母、数字和特定字符.-_*#!&+|^~'"/:;,=@?<>等

  • 当为删除动作时,可不填

action

String

参数解释:

设置HTTP响应头操作类型

取值范围:

  • set: 设置

  • delete: 删除

表11 AccessControl

参数

参数类型

描述

type

String

参数解释:

访问控制类型

取值范围:

  • block: 拒绝

  • trust: 允许

表12 RequestLimitRulesEngine

参数

参数类型

描述

limit_rate_after

Long

参数解释:

限速条件

说明:
例如:type=size,limit_rate_after=50表示从传输50个字节后开始限速且限速值为limit_rate_value

取值范围:

0-1073741824,单位:byte

limit_rate_value

Integer

参数解释:

限速值,即达到限速条件后的最大访问速度

取值范围:

0-104857600,单位:Bps

表13 OriginRequestUrlRewriteEngine

参数

参数类型

描述

rewrite_type

String

参数解释:

改写方式

取值范围:

  • simple: 精确改写

  • wildcard: 捕获改写

  • regex: 正则改写(白名单功能,请提交工单开放该配置)

source_url

String

参数解释:

需要替换的URI

取值范围:

  • 1-512个字符

  • 支持通配符*匹配,如:/test/*/*.mp4

  • 以正斜线(/)开头的URI,不含http(s)://头及域名

target_url

String

参数解释:

替换后的URI

取值范围:

  • 1-256个字符

  • 以正斜线(/)开头的URI,不含http(s)://头及域名

说明:
通配符 * 可通过$n捕获(n=1,2,3...,例如:/newtest/$1/$2.jpg)
表14 CacheRulesEngine

参数

参数类型

描述

ttl

Integer

参数解释:

资源在CDN节点的缓存过期时间

取值范围:

不涉及

ttl_unit

String

参数解释:

缓存过期时间单位

取值范围:

  • s: 秒

  • m: 分

  • h: 小时

  • d: 天

follow_origin

String

参数解释:

缓存过期时间来源,设置CDN节点的缓存遵循源站还是CDN侧的配置

取值范围:

  • on: CDN节点的缓存过期时间遵循源站的设置

  • off: CDN节点的缓存过期时间遵循“缓存规则”中的“缓存过期时间”

  • min_ttl: CDN节点的缓存过期时间取缓存规则和源站二者的最小值

force_cache

String

参数解释:

强制缓存:CDN节点缓存过期时间是否忽略源站响应头Cache-Control中的no-cache、private、no-store字段

取值范围:

  • on: 打开强制缓存

  • off: 关闭强制缓存

表15 RequestUrlRewriteEngine

参数

参数类型

描述

redirect_status_code

Integer

参数解释:

重定向状态码

取值范围:

  • 301

  • 302

  • 303

  • 307

redirect_url

String

参数解释:

重定向URL

取值范围:

不涉及

redirect_host

String

参数解释:

支持将客户端请求重定向到其他域名

取值范围:

  • 1-255个字符

  • 必须以http://或https://开头

execution_mode

String

参数解释:

执行规则

取值范围:

  • redirect: 如果请求的URL匹配了当前规则,该请求将被重定向到目标Path。执行完当前规则后,当存在其他配置规则时,会继续匹配剩余规则

  • break: 如果请求的URL匹配了当前规则,请求将被改写为目标Path。执行完当前规则后,当存在其他配置规则时,将不再匹配剩余规则,此时不支持配置重定向Host和重定向状态码,返回状态码200

表16 BrowserCacheRulesEngine

参数

参数类型

描述

cache_type

String

参数解释:

缓存生效类型

取值范围:

  • follow_origin: 遵循源站的缓存策略,即Cache-Control头部的设置

  • ttl: 浏览器缓存遵循当前规则设置的过期时间

  • never: 浏览器不缓存资源

ttl

Integer

参数解释:

缓存过期时间

取值范围:

不涉及

ttl_unit

String

参数解释:

缓存过期时间单位

取值范围:

  • s:秒

  • m:分钟

  • h:小时

  • d:天

表17 ErrorCodeCacheEngine

参数

参数类型

描述

code

Integer

参数解释:

需要缓存的错误码

取值范围:

  • 3xx: 301, 302

  • 4xx: 400, 403, 404, 405, 414

  • 5xx: 501, 502, 503, 504

ttl

Integer

参数解释:

错误码缓存时间

取值范围:

0-31536000,单位:秒

说明:
3XX状态码缓存时间范围为0-20s

请求示例

GET https://cdn.myhuaweicloud.com/v1.0/cdn/configuration/domains/www.example.com/rules

响应示例

状态码:200

请求成功

{
  "rules" : [ {
    "rule_id" : "example***********************id",
    "name" : "example",
    "status" : "on",
    "priority" : 1,
    "conditions" : {
      "match" : {
        "logic" : "and",
        "criteria" : [ {
          "match_target_type" : "scheme",
          "match_target_name" : "example",
          "match_type" : "contains",
          "match_pattern" : [ "HTTP" ],
          "negate" : false,
          "case_sensitive" : false
        } ]
      }
    }
  } ]
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.GlobalCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cdn.v2.region.CdnRegion;
import com.huaweicloud.sdk.cdn.v2.*;
import com.huaweicloud.sdk.cdn.v2.model.*;


public class ListRuleDetailsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new GlobalCredentials()
                .withAk(ak)
                .withSk(sk);

        CdnClient client = CdnClient.newBuilder()
                .withCredential(auth)
                .withRegion(CdnRegion.valueOf("<YOUR REGION>"))
                .build();
        ListRuleDetailsRequest request = new ListRuleDetailsRequest();
        request.withDomainName("{domain_name}");
        try {
            ListRuleDetailsResponse response = client.listRuleDetails(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import GlobalCredentials
from huaweicloudsdkcdn.v2.region.cdn_region import CdnRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcdn.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = GlobalCredentials(ak, sk)

    client = CdnClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CdnRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListRuleDetailsRequest()
        request.domain_name = "{domain_name}"
        response = client.list_rule_details(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
    cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth, err := global.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := cdn.CdnClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := cdn.NewCdnClient(hcClient)

    request := &model.ListRuleDetailsRequest{}
	request.DomainName = "{domain_name}"
	response, err := client.ListRuleDetails(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求成功

错误码

请参见错误码

相关文档