カスタムルールセットをデプロイするには、アカウントまたはゾーンレベルのフェーズ エントリポイントルールセット のルール一覧に、execute アクションのルールを追加します。新しいルールの式が、カスタムルールセットの実行タイミングを決めます。
カスタムルールセットは、同じスコープのエントリポイントルールセットにだけデプロイできます。たとえば、アカウントレベルで定義したカスタムルールセットは、アカウントレベルにだけデプロイできます。
Terraform を使っている場合は、カスタムルールセットの作成とデプロイの例について Terraform による WAF カスタムルールの設定 を参照してください。
Cloudflare ダッシュボードを使っている場合は、ダッシュボードでカスタムルールセットを操作する を参照してください。
- カスタムルールセットをデプロイする フェーズ の名前を確認します。
- カスタムルールセットを作成 し、新しいカスタムルールセットの ID を控えます。
- フェーズエントリポイントルールセットに既にあるルールを取得 します。残したい既存ルールは、すべて
PUTリクエストに含める必要があります。
次の PUT リクエストは、ゾーン名が example.com に一致するときにカスタムルールセットを実行するルールを追加します。
PUT リクエストには、残したい既存ルールの ID をすべて含めてください。レスポンスには、更新後のフェーズエントリポイントルールセットの全ルールが含まれます。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteTransform Rules WriteSelect Configuration WriteAccount WAF WriteAccount Rulesets WriteLogs Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets/phases/http_request_firewall_custom/entrypoint" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"rules": [
{
"action": "execute",
"description": "Execute custom ruleset",
"expression": "(cf.zone.name == \"example.com\") and cf.zone.plan eq \"ENT\"",
"action_parameters": {
"id": "<CUSTOM_RULESET_ID>"
}
},
{
"id": "<EXISTING_PHASE_RULE_ID_1>"
},
{
"id": "<EXISTING_PHASE_RULE_ID_2>"
}
]
}'{
"result": {
"id": "<ACCOUNT_PHASE_RULESET_ID>",
"name": "http_request_firewall_custom phase entry point ruleset for my account",
"description": "Execute several rulesets",
"kind": "root",
"version": "3",
"rules": [
{
"id": "<PHASE_RULE_ID>",
"version": "1",
"action": "execute",
"description": "Execute custom ruleset",
"action_parameters": {
"id": "<CUSTOM_RULESET_ID>",
"version": "latest"
},
"expression": "(cf.zone.name == \"example.com\") and cf.zone.plan eq \"ENT\"",
"last_updated": "2021-03-18T18:35:14.135697Z",
"ref": "<PHASE_RULE_REF>",
"enabled": true
},
{
"id": "<EXISTING_PHASE_RULE_ID_1>",
"version": "1",
"action": "execute",
"action_parameters": {
"id": "<EXECUTED_RULESET_ID_1>",
"version": "latest"
},
"expression": "(cf.zone.name eq \"example.com\") and cf.zone.plan eq \"ENT\"",
"last_updated": "2021-03-16T15:51:49.180378Z",
"ref": "<EXISTING_PHASE_RULE_REF_1>",
"enabled": true
},
{
"id": "<EXISTING_PHASE_RULE_ID_2>",
"version": "1",
"action": "execute",
"action_parameters": {
"id": "<EXECUTED_RULESET_ID_2>",
"version": "latest"
},
"expression": "(cf.zone.name eq \"example.com\") and cf.zone.plan eq \"ENT\"",
"last_updated": "2021-03-16T15:50:29.861157Z",
"ref": "<EXISTING_PHASE_RULE_REF_2>",
"enabled": true
}
],
"last_updated": "2021-03-18T18:35:14.135697Z",
"phase": "http_request_firewall_custom"
},
"success": true,
"errors": [],
"messages": []
}次の PUT リクエストは、ゾーンレベルのエントリポイントルールセットにルールを追加します。URI パス /login を対象とするリクエストに対して、ID "<CUSTOM_RULESET_ID>" のカスタムルールセットを実行します。
PUT リクエストには、残したい既存ルールの ID をすべて含めてください。レスポンスには、更新後のフェーズエントリポイントルールセットの全ルールが含まれます。
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteConfig Settings WriteDynamic URL Redirects WriteCache Settings WriteCustom Errors WriteOrigin WriteManaged headers WriteZone Transform Rules WriteMass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset WriteSanitize WriteTransform Rules WriteSelect Configuration WriteBot Management WriteZone WAF WriteAccount WAF WriteAccount Rulesets WriteLogs WriteLogs Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/phases/http_request_firewall_custom/entrypoint" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"rules": [
{
"action": "execute",
"description": "Execute custom ruleset (zone)",
"expression": "(http.request.uri.path eq \"/login\")",
"action_parameters": {
"id": "<CUSTOM_RULESET_ID>"
}
},
{
"id": "<EXISTING_PHASE_RULE_ID_1>"
}
]
}'{
"result": {
"id": "<ZONE_PHASE_RULESET_ID>",
"name": "http_request_firewall_custom phase entry point ruleset for my zone",
"description": "",
"kind": "zone",
"version": "3",
"rules": [
{
"id": "<PHASE_RULE_ID>",
"version": "1",
"action": "execute",
"description": "Execute custom ruleset (zone)",
"action_parameters": {
"id": "<CUSTOM_RULESET_ID>",
"version": "latest"
},
"expression": "(http.request.uri.path eq \"/login\")",
"last_updated": "2025-08-18T18:35:14.135697Z",
"ref": "<PHASE_RULE_REF>",
"enabled": true
},
{
"id": "<EXISTING_PHASE_RULE_ID_1>",
"version": "1",
"action": "managed_challenge",
"expression": "(cf.waf.score lt 20 and http.request.uri.path wildcard \"/admin/*\")",
"last_updated": "2025-08-16T15:51:49.180378Z",
"ref": "<EXISTING_PHASE_RULE_REF_1>",
"enabled": true
}
],
"last_updated": "2025-08-18T18:35:14.135697Z",
"phase": "http_request_firewall_custom"
},
"success": true,
"errors": [],
"messages": []
}