PUT
/
cdn
/
resources
/
{resource_id}
/
rules
/
{rule_id}
Change rule
curl --request PUT \
  --url https://api.gcore.com/cdn/resources/{resource_id}/rules/{rule_id} \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "active": true,
  "name": "My first rule",
  "rule": "/folder/images/*.png",
  "ruleType": 0,
  "weight": 1,
  "overrideOriginProtocol": null,
  "originGroup": null,
  "options": {
    "allowedHttpMethods": {
      "enabled": true,
      "value": [
        "GET",
        "POST"
      ]
    },
    "bot_protection": {
      "enabled": true,
      "bot_challenge": {
        "enabled": true
      }
    },
    "brotli_compression": {
      "enabled": true,
      "value": [
        "text/html",
        "text/plain"
      ]
    },
    "browser_cache_settings": {
      "enabled": true,
      "value": "3600s"
    },
    "cache_http_headers": {
      "enabled": false,
      "value": [
        "vary",
        "content-length",
        "last-modified",
        "connection",
        "accept-ranges",
        "content-type",
        "content-encoding",
        "etag",
        "cache-control",
        "expires",
        "keep-alive",
        "server"
      ]
    },
    "cors": {
      "enabled": true,
      "value": [
        "domain.com",
        "domain2.com"
      ],
      "always": true
    },
    "country_acl": {
      "enabled": true,
      "policy_type": "allow",
      "excepted_values": [
        "GB",
        "DE"
      ]
    },
    "disable_cache": {
      "enabled": true,
      "value": false
    },
    "disable_proxy_force_ranges": {
      "enabled": true,
      "value": true
    },
    "edge_cache_settings": {
      "enabled": true,
      "value": "43200s",
      "custom_values": {
        "100": "43200s"
      }
    },
    "fastedge": {
      "enabled": true,
      "on_request_headers": {
        "enabled": true,
        "app_id": "1001",
        "interrupt_on_error": true
      }
    },
    "fetch_compressed": {
      "enabled": true,
      "value": false
    },
    "follow_origin_redirect": {
      "enabled": true,
      "codes": [
        302,
        308
      ]
    },
    "force_return": {
      "enabled": true,
      "code": 301,
      "body": "http://example.com/redirect_address",
      "time_interval": {
        "start_time": "09:00",
        "end_time": 1200,
        "time_zone": "CET"
      }
    },
    "forward_host_header": {
      "enabled": false,
      "value": false
    },
    "gzipOn": {
      "enabled": true,
      "value": true
    },
    "hostHeader": {
      "enabled": true,
      "value": "host.com"
    },
    "ignore_cookie": {
      "enabled": true,
      "value": true
    },
    "ignoreQueryString": {
      "enabled": true,
      "value": false
    },
    "image_stack": {
      "enabled": true,
      "avif_enabled": true,
      "webp_enabled": false,
      "quality": 80,
      "png_lossless": true
    },
    "ip_address_acl": {
      "enabled": true,
      "policy_type": "deny",
      "excepted_values": [
        "192.168.1.100/32"
      ]
    },
    "limit_bandwidth": {
      "enabled": true,
      "limit_type": "static",
      "speed": 100,
      "buffer": 200
    },
    "proxy_cache_key": {
      "enabled": true,
      "value": "$scheme$uri"
    },
    "proxy_cache_methods_set": {
      "enabled": true,
      "value": false
    },
    "proxy_connect_timeout": {
      "enabled": true,
      "value": "4s"
    },
    "proxy_read_timeout": {
      "enabled": true,
      "value": "10s"
    },
    "query_params_blacklist": {
      "enabled": true,
      "value": [
        "some",
        "blacklisted",
        "query"
      ]
    },
    "query_params_whitelist": {
      "enabled": true,
      "value": [
        "some",
        "whitelisted",
        "query"
      ]
    },
    "query_string_forwarding": {
      "enabled": true,
      "forward_from_file_types": [
        "m3u8",
        "mpd"
      ],
      "forward_to_file_types": [
        "ts",
        "mp4"
      ]
    },
    "redirect_http_to_https": {
      "enabled": true,
      "value": true
    },
    "redirect_https_to_http": {
      "enabled": false,
      "value": true
    },
    "referrer_acl": {
      "enabled": true,
      "policy_type": "deny",
      "excepted_values": [
        "example.com",
        "*.example.net"
      ]
    },
    "request_limiter": {
      "enabled": true,
      "rate_unit": "r/s",
      "rate": 5,
      "burst": 5,
      "delay": 0
    },
    "response_headers_hiding_policy": {
      "enabled": true,
      "mode": "hide",
      "excepted": [
        "my-header"
      ]
    },
    "rewrite": {
      "enabled": true,
      "body": "/(.*) /additional_path/$1",
      "flag": "break"
    },
    "secure_key": {
      "enabled": true,
      "key": "secretkey",
      "type": 2
    },
    "slice": {
      "enabled": true,
      "value": true
    },
    "sni": {
      "enabled": true,
      "sni_type": "custom",
      "custom_hostname": "custom.example.com"
    },
    "stale": {
      "enabled": true,
      "value": [
        "http_404",
        "http_500"
      ]
    },
    "static_response_headers": {
      "enabled": true,
      "value": [
        {
          "name": "X-Example",
          "value": [
            "Value_1"
          ],
          "always": true
        },
        {
          "name": "X-Example-Multiple",
          "value": [
            "Value_1",
            "Value_2",
            "Value_3"
          ],
          "always": false
        }
      ]
    },
    "staticHeaders": {
      "enabled": true,
      "value": {
        "X-Example": "Value_1",
        "X-Example-Multiple": [
          "Value_2",
          "Value_3"
        ]
      }
    },
    "staticRequestHeaders": {
      "enabled": true,
      "value": {
        "Header-One": "Value 1",
        "Header-Two": "Value 2"
      }
    },
    "user_agent_acl": {
      "enabled": true,
      "policy_type": "allow",
      "excepted_values": [
        "UserAgent Value",
        ""
      ]
    },
    "websockets": {
      "enabled": true,
      "value": true
    }
  }
}'
{
  "id": 5,
  "name": "My first rule",
  "active": true,
  "deleted": false,
  "originGroup": null,
  "rule": "/folder/images/*.png",
  "ruleType": 0,
  "weight": 1,
  "originProtocol": "HTTPS",
  "overrideOriginProtocol": null,
  "preset_applied": false,
  "primary_rule": null,
  "options": {
    "allowedHttpMethods": {
      "enabled": true,
      "value": [
        "GET",
        "POST"
      ]
    },
    "bot_protection": {
      "enabled": true,
      "bot_challenge": {
        "enabled": true
      }
    },
    "brotli_compression": {
      "enabled": true,
      "value": [
        "text/html",
        "text/plain"
      ]
    },
    "browser_cache_settings": {
      "enabled": true,
      "value": "3600s"
    },
    "cache_http_headers": {
      "enabled": false,
      "value": [
        "vary",
        "content-length",
        "last-modified",
        "connection",
        "accept-ranges",
        "content-type",
        "content-encoding",
        "etag",
        "cache-control",
        "expires",
        "keep-alive",
        "server"
      ]
    },
    "cors": {
      "enabled": true,
      "value": [
        "domain.com",
        "domain2.com"
      ],
      "always": true
    },
    "country_acl": {
      "enabled": true,
      "policy_type": "allow",
      "excepted_values": [
        "GB",
        "DE"
      ]
    },
    "disable_cache": {
      "enabled": true,
      "value": false
    },
    "disable_proxy_force_ranges": {
      "enabled": true,
      "value": true
    },
    "edge_cache_settings": {
      "enabled": true,
      "value": "43200s",
      "custom_values": {
        "100": "43200s"
      }
    },
    "fastedge": {
      "enabled": true,
      "on_request_headers": {
        "enabled": true,
        "app_id": "1001",
        "interrupt_on_error": true
      }
    },
    "fetch_compressed": {
      "enabled": true,
      "value": false
    },
    "follow_origin_redirect": {
      "enabled": true,
      "codes": [
        302,
        308
      ]
    },
    "force_return": {
      "enabled": true,
      "code": 301,
      "body": "http://example.com/redirect_address",
      "time_interval": {
        "start_time": "09:00",
        "end_time": 1200,
        "time_zone": "CET"
      }
    },
    "forward_host_header": {
      "enabled": false,
      "value": false
    },
    "gzipOn": {
      "enabled": true,
      "value": true
    },
    "hostHeader": {
      "enabled": true,
      "value": "host.com"
    },
    "ignore_cookie": {
      "enabled": true,
      "value": true
    },
    "ignoreQueryString": {
      "enabled": true,
      "value": false
    },
    "image_stack": {
      "enabled": true,
      "avif_enabled": true,
      "webp_enabled": false,
      "quality": 80,
      "png_lossless": true
    },
    "ip_address_acl": {
      "enabled": true,
      "policy_type": "deny",
      "excepted_values": [
        "192.168.1.100/32"
      ]
    },
    "limit_bandwidth": {
      "enabled": true,
      "limit_type": "static",
      "speed": 100,
      "buffer": 200
    },
    "proxy_cache_key": {
      "enabled": true,
      "value": "$scheme$uri"
    },
    "proxy_cache_methods_set": {
      "enabled": true,
      "value": false
    },
    "proxy_connect_timeout": {
      "enabled": true,
      "value": "4s"
    },
    "proxy_read_timeout": {
      "enabled": true,
      "value": "10s"
    },
    "query_params_blacklist": {
      "enabled": true,
      "value": [
        "some",
        "blacklisted",
        "query"
      ]
    },
    "query_params_whitelist": {
      "enabled": true,
      "value": [
        "some",
        "whitelisted",
        "query"
      ]
    },
    "query_string_forwarding": {
      "enabled": true,
      "forward_from_file_types": [
        "m3u8",
        "mpd"
      ],
      "forward_to_file_types": [
        "ts",
        "mp4"
      ]
    },
    "redirect_http_to_https": {
      "enabled": true,
      "value": true
    },
    "redirect_https_to_http": {
      "enabled": false,
      "value": true
    },
    "referrer_acl": {
      "enabled": true,
      "policy_type": "deny",
      "excepted_values": [
        "example.com",
        "*.example.net"
      ]
    },
    "request_limiter": {
      "enabled": true,
      "rate_unit": "r/s",
      "rate": 5,
      "burst": 5,
      "delay": 0
    },
    "response_headers_hiding_policy": {
      "enabled": true,
      "mode": "hide",
      "excepted": [
        "my-header"
      ]
    },
    "rewrite": {
      "enabled": true,
      "body": "/(.*) /additional_path/$1",
      "flag": "break"
    },
    "secure_key": {
      "enabled": true,
      "key": "secretkey",
      "type": 2
    },
    "slice": {
      "enabled": true,
      "value": true
    },
    "sni": {
      "enabled": true,
      "sni_type": "custom",
      "custom_hostname": "custom.example.com"
    },
    "stale": {
      "enabled": true,
      "value": [
        "http_404",
        "http_500"
      ]
    },
    "static_response_headers": {
      "enabled": true,
      "value": [
        {
          "name": "X-Example",
          "value": [
            "Value_1"
          ],
          "always": true
        },
        {
          "name": "X-Example-Multiple",
          "value": [
            "Value_1",
            "Value_2",
            "Value_3"
          ],
          "always": false
        }
      ]
    },
    "staticHeaders": {
      "enabled": true,
      "value": {
        "X-Example": "Value_1",
        "X-Example-Multiple": [
          "Value_2",
          "Value_3"
        ]
      }
    },
    "staticRequestHeaders": {
      "enabled": true,
      "value": {
        "Header-One": "Value 1",
        "Header-Two": "Value 2"
      }
    },
    "user_agent_acl": {
      "enabled": true,
      "policy_type": "allow",
      "excepted_values": [
        "UserAgent Value",
        ""
      ]
    },
    "websockets": {
      "enabled": true,
      "value": true
    }
  }
}

Authorizations

Authorization
string
header
required

API key for authentication. Make sure to include the word apikey, followed by a single space and then your token. Example: apikey 1234$abcdef

Path Parameters

resource_id
integer
required

CDN resource ID.

rule_id
integer
required

Rule ID.

Body

application/json
rule
string
required

Path to the file or folder for which the rule will be applied. The rule is applied if the requested URI matches the rule path. We add a leading forward slash to any rule path. Specify a path without a forward slash.

Maximum length: 300
Example:

"/folder/images/*.png"

ruleType
integer
required

Rule type. Possible values:

  • Type 0 - Regular expression. Must start with '^/' or '/'.
  • Type 1 - Regular expression. Note that for this rule type we automatically add / to each rule pattern before your regular expression. This type is legacy, please use Type 0.
Required range: 0 <= x <= 1
Example:

0

active
boolean

Enables or disables a rule. Possible values:

  • true - Rule is active, rule settings are applied.
  • false - Rule is inactive, rule settings are not applied.
Example:

true

name
string

Rule name.

Maximum length: 255
Example:

"My first rule"

weight
integer

Rule execution order: from lowest (1) to highest. If requested URI matches multiple rules, the one higher in the order of the rules will be applied.

Required range: 1 <= x <= 2147483647
Example:

1

overrideOriginProtocol
enum<string> | null

Sets a protocol other than the one specified in the CDN resource settings to connect to the origin. Possible values:

  • HTTPS - CDN servers connect to origin via HTTPS protocol.
  • HTTP - CDN servers connect to origin via HTTP protocol.
  • MATCH - Connection protocol is chosen automatically; in this case, content on origin source should be available for the CDN both through HTTP and HTTPS protocols.
  • null - originProtocol setting is inherited from the CDN resource settings.
Available options:
HTTPS,
HTTP,
MATCH
Example:

null

originGroup
integer | null

ID of the origin group to which the rule is applied. If the origin group is not specified, the rule is applied to the origin group that the CDN resource is associated with.

Example:

null

options
object

List of options that can be configured for the rule. In case of null value the option is not added to the rule. Option inherits its value from the CDN resource settings.

Response

Successful.

id
integer

Rule ID.

Example:

5

name
string

Rule name.

Maximum length: 255
Example:

"My first rule"

active
boolean

Enables or disables a rule. Possible values:

  • true - Rule is active, rule settings are applied.
  • false - Rule is inactive, rule settings are not applied.
Example:

true

deleted
boolean

Defines whether the rule has been deleted. Possible values:

  • true - Rule has been deleted.
  • false - Rule has not been deleted.
Example:

false

originGroup
integer | null

ID of the origin group to which the rule is applied. If the origin group is not specified, the rule is applied to the origin group that the CDN resource is associated with.

Example:

null

rule
string

Path to the file or folder for which the rule will be applied. The rule is applied if the requested URI matches the rule path. We add a leading forward slash to any rule path. Specify a path without a forward slash.

Maximum length: 300
Example:

"/folder/images/*.png"

ruleType
integer

Rule type. Possible values:

  • Type 0 - Regular expression. Must start with '^/' or '/'.
  • Type 1 - Regular expression. Note that for this rule type we automatically add / to each rule pattern before your regular expression. This type is legacy, please use Type 0.
Required range: 0 <= x <= 1
Example:

0

weight
integer

Rule execution order: from lowest (1) to highest. If requested URI matches multiple rules, the one higher in the order of the rules will be applied.

Required range: 1 <= x <= 2147483647
Example:

1

originProtocol
enum<string>

Protocol used by CDN servers to request content from an origin source. Possible values:

  • HTTPS - CDN servers connect to origin via HTTPS protocol.
  • HTTP - CDN servers connect to origin via HTTP protocol.
  • MATCH - Connection protocol is chosen automatically; in this case, content on origin source should be available for the CDN both through HTTP and HTTPS protocols.
Available options:
HTTPS,
HTTP,
MATCH
Example:

"HTTPS"

overrideOriginProtocol
enum<string> | null

Sets a protocol other than the one specified in the CDN resource settings to connect to the origin. Possible values:

  • HTTPS - CDN servers connect to origin via HTTPS protocol.
  • HTTP - CDN servers connect to origin via HTTP protocol.
  • MATCH - Connection protocol is chosen automatically; in this case, content on origin source should be available for the CDN both through HTTP and HTTPS protocols.
  • null - originProtocol setting is inherited from the CDN resource settings.
Available options:
HTTPS,
HTTP,
MATCH
Example:

null

preset_applied
boolean

Defines whether the rule has an applied preset. Possible values:

  • true - Rule has a preset applied.
  • false - Rule does not have a preset applied. If a preset is applied to the rule, the options included in the preset cannot be edited for the rule.
Example:

false

primary_rule
integer | null

ID of the rule with which the current rule is synchronized within the CDN resource shared cache zone feature.

Example:

null

options
object

List of options that can be configured for the rule. In case of null value the option is not added to the rule. Option inherits its value from the CDN resource settings.