[Yandex Cloud documentation](../../index.md) > [Yandex Cloud CDN](../index.md) > [Concepts](index.md) > Location rules

# Location rules Yandex Cloud CDN

_Location rules_ are a mechanism used to selectively redefine [CDN resource](resource.md) settings for requests whose paths match a specific template.

> Let’s assume that [content caching](caching.md) 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:
* [Origin group](origins.md)
* [Content caching](caching.md)
* [Request redirect](http-rewrite.md)
* [Parameters of access via secure tokens](secure-tokens.md)
* [IP-based access policy](ip-address-acl.md)
* [HTTP request and response headers](../operations/resources/configure-headers.md)
* [Allowed HTTP methods for client requests](../operations/resources/configure-http.md)
* [Cross-domain CORS requests](cors.md)
* [Content compression](compression.md)
* [Content segmentation](slicing.md)
* [Non-standard HTTP responses](../operations/resources/configure-response.md)

{% note info %}

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](../operations/resources/location-rules.md#setup).

{% endnote %}

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.

  {% note tip %}
  
  To explicitly indicate the start or end of the string to match in a regular expression, use the `^` and `$` anchor characters.
  
  {% endnote %}

* _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.

  <br>

  > For example, let’s assume you set the following location rules:
  >
  > | Rule | Weight | Regular expression | Cache lifetime |
  > | --- | --- | --- | --- |
  > | A | `1` | `^/path/.+` | `1 hour` |
  > | B | `2` | `\.txt$` | `4 hours` |
  >
  > With this configuration, the `/path/file.txt` request 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.txt` file for four hours, rule B must have a lower weight than rule A.

For the full list of location rule parameters, see the [API](../api-ref/ResourceRules/create.md) specification.

You can configure location rules in the [management console](https://console.yandex.cloud) or using the [API](../api-ref/ResourceRules/index.md). For more information, see [Setting up Yandex Cloud CDN location rules](../operations/resources/location-rules.md).

## See also {#see-also}

* [CDN resource](resource.md)
* [Content caching](caching.md)
* [Redirecting requests](http-rewrite.md)
* [Secure tokens](secure-tokens.md)
* [IP-based access policy](ip-address-acl.md)
* [Setting up Yandex Cloud CDN location rules](../operations/resources/location-rules.md)