Location rules Yandex Cloud CDN
Warning
The location rule functionality is only available through the Yandex Cloud CDN provider.
Location rules are a mechanism used to selectively redefine CDN resource settings for requests whose paths match a specific template.
Let’s assume that content caching is enabled in the CDN resource settings, while cache lifetime is set to four days. This is enough for most types of content, but for some specific files you have to reduce cache lifetime to a few seconds. Location rules will help you with such cases.
You can use location rules to override the following CDN resource settings:
- Content caching
- Redirecting requests
- Parameters of access via secure tokens
- IP-based access policy
- HTTP request and response headers
- Allowed HTTP methods for client requests
- Cross-domain CORS requests
- Content compression
- Content segmentation
Note
The settings of HTTP headers and methods, CORS, content compression and segmentation, as well as advanced content caching options, become available after you create a location rule. For more details, see Setting additional parameters.
For each location rule, specify the following parameters:
-
Regular expression: URI path pattern against which requests are checked. If there is a match, the settings specific to that location rule will apply.
Tip
To explicitly indicate the start or end of the string to match in a regular expression, use the
^and$anchor characters. -
Rule weight: Rule triggering priority. The lower a rule’s weight, the higher its priority in the user resource configuration. If multiple rules have the same weight, they will be applied in a random order.
For example, let’s assume you set the following location rules:
Rule Weight Regular expression Cache lifetime A 1^/path/.+1 hourB 2\.txt$4 hoursWith this configuration, the
/path/file.txtrequest will match rule A, which has a lower weight and a higher priority than rule B, so the file will be cached for one hour.To cache the
/path/file.txtfile for four hours, rule B must have a lower weight than rule A.
For the full list of location rule parameters, see the API specification.
You can configure location rules in the management console