Page Rules
To use the Arvancloud CDN, you simply add your domain in the panel and turn on the cloud icon of its record; the system then automatically applies the default settings to all subdomains. For example, your static files are cached.
If you want to change the CDN's default behavior (for example, so a specific file is not cached or a specific header is ignored), you need to create a rule for that page in Page Rules.
To create and manage page rules, select CDN from the products menu, then click Page Rules.
There is a default rule that all requests to the root domain and its subdomains match, and based on this rule, the Caching, WAF, Firewall, and other settings are applied to the domain's requests.
Rules must be built with the pattern scheme://hostname/path, for example:
https://subdomain.test.com/somepage
An important point about page rules is that a request matches only one rule (the first rule that matches the pattern), and all desired settings must be placed in that rule. Rules are checked from top to bottom.
Now imagine there is a website at dev.test.com and you want to disable caching on the website's /static/ path so you can see changes to static files immediately.
To do this, create a rule with the address dev.test.com/static/* and turn off caching in it.
Note that for a wildcard, you must use * so that every request starting with dev.test.com/static/ matches this rule.
The new rule then appears in your list of page rules, above the default rule.
Using Regular Expressions in Rules
If you want to match specific characters (letters and numbers) with a rule, you can use square brackets [].
Example 1: Imagine you want to define a rule that covers both of the following URLs at the same time:
https://www.example.com/fa
https://www.example.com/Fa
To do this, when defining a new rule, enter the following in the address field:
https://example.com/[fF]a/*
Example 2: Imagine you want to set a rule that matches a URL like the following, which contains a number:
https://example.com/users/2xxxx
To do this, use a rule like the following:
https://example.com/users/[0-9]*
Example 3: Imagine you want to define a rule that matches all pages starting with lowercase letters in the a-z range. For this, you can use a rule like the following:
https://example.com/[a-z]/*
Note that if, along with the rule above, you also want all pages starting with uppercase letters in the A-Z range to match, you need to define a new rule for this in addition to the rule above and put A-Z instead of a-z inside the brackets.
Note that rules are case-sensitive.
If http or https is not specified at the beginning of a rule, by default the rule matches both HTTP and HTTPS URLs. For example:
www.example.com/*
If you want a rule to apply only to your home page, define the rule as follows:
www.example.com/
The following features are available in page rules:
Caching Settings
-
Browser cache TTL
-
Turning caching on or off and its settings
-
Ignore Vary
The Vary header in HTTP responses tells the server that the sent content may differ based on one or more request headers from the client. This header helps browsers and caching systems cache the correct versions of a resource.
For example, if a server provides a web page in both Persian and English, by sending the
Vary: Accept-Languageheader it tells the cache that, to cache this page, it must also consider the Accept-Language header in the client's request. This prevents showing the wrong content (for example, showing the English version to a Persian-speaking user) and lets caching systems manage different versions of a resource correctly.You can ignore the
varyheader in the cache settings so that different versions are not cached. -
Cache by device type
When you enable this feature, different versions are cached on the CDN for mobile and desktop. This is equivalent to
vary: user-agent.
Web Acceleration
If the website's content needs acceleration, you can enable acceleration in this section.
Note that acceleration can only be enabled for static files such as css, js, jpg, png, and gif (content that can be compressed and minified).
Image Resize
The CDN server shows images to visitors in the most suitable dimensions and takes the extra load off your server.
Proxy Settings
-
Send to Load Balancer
With this feature, you can use a different origin for a specific rule than the one defined in DNS. (This requires at least one cluster in the Load Balancing section.)
-
Header Settings
- Custom Host Header: Here you can set a custom Host header.
- Header sent to the user: Here you can specify that a new header is sent to the user (such as allow-access-origin).
- Header sent to the origin: Here you can send a specific header to your origin server (such as the Host header).
- Ignore header sent to the user: Here you can specify that a header sent by your server stays hidden from the user.
-
URL Rewrite
A server-side operation that converts the source URL to another URL. This happens before the web server fully processes a request. URL rewriting is not visible to website visitors, because the URL shown in the browser doesn't change.
Other Settings
-
Redirect
You can redirect requests with the status codes 301, 302, and 307.
-
Send traffic to Edge Computing
With this setting, you can send traffic to one of your edge computing applications.
-
Secure Link
If access to a domain or a specific URL must be limited to users with a specific IP and for a specific time, you can use this feature.
Purging Page Rule Cache
With this feature of the Arvancloud CDN, you can purge the cache of a specific page rule. This purge only covers the cache of files that were cached because of that page rule, and no change is made to other files of the site, subdomain, or other page rules.
To purge the cache of a page rule, go to Page Rules in the CDN product of the Arvancloud panel. Then select Purge Cache and confirm it to purge the cache of the selected rule.
This feature is only available on the CDN Professional and Enterprise plans, and you need to upgrade your service to use it.
Redirect Using Variables
With the Arvancloud CDN page rule settings, you can apply advanced settings to automatic redirection of user requests from one domain to another, which is done with the codes 301, 302, and 307. With variables, which can be applied to addresses without limit, addressing a request's destination is easier and more flexible. To learn how to set this up, see the Redirect guide.
Timeout Settings
With the Timeout settings, which can be defined as a rule, you can change the default timeout for the connection between Arvancloud CDN edge servers and the origin server. With this feature, you can change the timeout for three different stages:
- Connecting CDN edge servers to the website's origin server (Connection Timeout)
- Waiting to receive a response to the request sent to the origin server (Read Timeout)
- Writing data to the origin server (Write Timeout)
To do this, simply define a new rule in Page Rules in the Arvancloud panel, and after entering the address and priority, select Timeout Settings from the available settings. Then enter your desired value in seconds for each of Read Timeout, Connection Timeout, and Write Timeout, and finally click Add Rule.
Note that the Timeout settings are available on the Professional and Enterprise plans, and this plan must be active on your account to use it.
To change request or response buffering for specific paths, read the Request and Response Buffering guide.
Origin Cache Control
When using a CDN, because a number of cache servers sit between the requesting browser and the website's origin server, user requests are answered by these servers. For this reason, you may need to specify caching settings from the website's origin server so the versions of content delivered to users are managed better. For example, you may want to change how long the cache is refreshed or a file is revalidated, or specify that some files on the origin server should not be cached on CDN edge servers. With the Origin Cache Control feature of the Arvancloud CDN, you can manage an important part of content caching settings from your website's origin server and have more flexibility over your content.
How Origin Cache Control Works
Normally, to cache website content, the Arvancloud CDN sends a request to the website's origin server. The origin server sends an HTTP response that shows the content's caching parameters. With Origin Cache Control, a Cache-Control header is added to this response, which gives CDN edge servers more precise instructions about each piece of content. These parameters can specify how long the content's cache is valid or for what types of requests caching is done.
Types of Cache-Control Header
The information in the Cache-Control header that Origin Cache Control can understand shows different parameters. The following parameters show how resources are cached:
-
Max-age: Lets the origin server specify the cache expiration time. After the specified time, in seconds, edge servers send a request to revalidate the cache.
-
Public: With this parameter in a response's header, the content is cached for all requests regardless of previous instructions, even if the content is of a non-cacheable type.
-
Private: If this parameter is in the header, the content is not cached by edge servers, and the response is intended for a specific request. So caching only happens in the browser.
-
No-cache: The content is stored on the servers, but for each request, full revalidation must be done.
-
No-store: The content is not cached anywhere, and for each request, the content must be fully sent and received from the requester to the origin server and back.
-
Min-uses: Specifies that edge servers cache the content after a specific number of requests for it.
-
S-max: Edge servers change the expiration time specified by max-age to the time specified in this parameter.
Note that for this scenario, if Cache Max Age is set to off, it takes priority over s-maxage. So you need to set a default value for Cache Max Age for the s-maxage value to apply.
-
Must-revalidate: Content with this parameter in its response header must be revalidated through the origin server once for each request.
For example, with parameters like the following in the header of an HTTP response, edge servers understand that this content must be stored on all servers and revalidated after 36000 seconds.
Control-Cache: public, max-age=36000
How to Enable Origin Cache Control
To enable Origin Cache Control, simply go to Page Rules in the CDN product of the Arvancloud panel. Then, by defining a page rule for a specific address or the whole domain, you can enable cache control.
Note that cache control is a feature of the Arvancloud CDN Professional plan, and if you use other plans, you need to upgrade your product's plan to use Origin Cache Control.