How to add a rule: basic settings
Use Rules to set up custom settings for certain file types or paths.
Please note that you cannot add a rule if the resource is prepared for use by the Streaming service.
1. In the resource settings, go to the Rules tab, click the Create rule button and choose Create blank rule.
2. Specify a rule name.
3. Specify a regular expression starting with ^/ or /
4. Origin pull protocol.
The option is added by default. You can change the source, or inherit it from a resource.
6. Click the Add option button in the Options section to select the required options.
How Rules interact with the resource settings
1. If options are not added in Rule, the options are inherited from the resource settings.
For example, if you do not add options in the Rule for caching settings, the caching settings for the content specified in the rule will be inherited from the resource settings.
2. If the option is added to Rule but disabled, it is disabled for the Rule.
If you add an option in a rule and disable it, the option will be disabled for the rule. The option parameters from the resource settings will not be taken into account for the content specified in the rule.
- In the resource settings, the Country access policy option is added with the Allow by default, RU values. It means that access to content is limited for Russia.
- In the Rule settings, the Country access policy option is added but disabled.
As a result, access for Russia will be limited to all content, except for that specified in the Rule settings.
3. If an option is added to a rule, its value set in the resource settings is overridden.
- In the resource settings, the Browser Caching option is added with the CDN controlled, 4 days values.
- In the Rule settings, the Browser Caching option is added with the CDN controlled, 30 minutes values.
The content specified in the Rule will be cached in the browser for 30 minutes, the rest of the content - for 4 days.
Rule creating from a template
You can create a rule from a prepared template.
1. In the resource settings, go to the Rules tab and click Create rule button.
2. Select the desired template: added by account users or a system template.
3. Make changes, if necessary, and save the rule.
For example, to forbid caching of jpg, css, js files in CDN enter .*.(jpg|css|js)$ to the Rule Pattern:
Add the CDN caching option with the CDN controlled and Do not cache values.
To set up HTTP-header Access-Control-Allow-Origin only for ttf files enter this to the Rule Pattern:
Add the CORS header support option.
You can add the header to all requests or just to the requests from the specified domains.
If a URI matches multiple rules the one that is higher in the order of the rules will be applied.
For example, there are 2 rules on the resource:
Rule 1: /folder/.*
Rule 2: /folder/image.jpg
That is, for the /folder/image file.jpg rule 1 will be applied.