通过 Cloudflare API 转发 URL

Dan*_*pin 4 api cloudflare

我正在尝试使用 Cloudflare 的 API 创建页面规则以将 http 转发到 https。不幸的是,我不认为文档是 100% 清楚如何做到这一点。这是我当前传递给 POST 正文的 JSON 对象:

{
  "targets": [
    {
      "target": "url",
      "constraint": {
        "operator": "matches",
        "value": "http://exampletest.com/*"
      }
    }
],
  "actions": [{
    "id": "forwarding_url",
    "value": "https://exampletest.com/$1"
  }]
}
Run Code Online (Sandbox Code Playgroud)

这是我要回来的消息:

{
"success": false,
"errors": [
    {
        "code": 1004,
        "message": "Page Rule validation failed: See messages for details."
    }
],
"messages": [
    {
        "code": 1,
        "message": ".settings[0].url: This value should not be blank.",
        "type": null
    },
    {
        "code": 2,
        "message": ".settings[0].statusCode: This value should not be blank.",
        "type": null
    }
],
"result": null
Run Code Online (Sandbox Code Playgroud)

}

所以看起来我需要在某处有一个设置对象,但是无论我尝试添加设置的任何方式,我都会收到相同的消息。有谁知道我在这里做错了什么?这是 Cloudflare 关于该主题的文档。不确定我是否可能遗漏了什么:

https://api.cloudflare.com/#page-rules-for-a-zone-create-page-rule

Dan*_*pin 5

其实,只是想通了这一点。看起来这是正确的格式:

{
  "targets": [
    {
      "target": "url",
      "constraint": {
        "operator": "matches",
        "value": "http://exampletest.com/*"
      }
    }
  ],
  "actions": [
    {
      "id": "forwarding_url",
      "value": {
        "url": "https://www.exampletest.com/$1",
        "status_code": 301
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)