StackPath offers custom Delivery Rules with every Site configured for CDN. EdgeRules provide users a great amount of flexibility to customize the behavior of the StackPath CDN. EdgeRules trigger upon receiving a request that matches the rules' specific conditions.
EdgeRules occur only on CDN requests, the EdgeRule response is added before the request is processed by the StackPath WAF, so every CDN EdgeRule will work in tandem to the WAF if both are in use.
Creating Custom EdgeRules
1. Log in to the StackPath control panel.
2. Navigate to the Site the EdgeRule will be created for.
3. Select the EdgeRules tab
4. Within this tab, the Delivery Rules section will be where custom EdgeRules for the CDN will be created. Select Add Delivery Rule to create a custom rule.
5. You will be prompted to define your EdgeRule with dropdowns for Conditions and Rules Options (as defined below).
Conditions are requirements that trigger EdgeRules to activate. The initial Condition will begin with an IF statement, and any subsequent conditions will be added with AND statements. The rule will only trigger if all specified conditions are met.
URL: The rule will trigger if the requested URL matches what is specified in this section. This also includes any specified file-paths or file types.
Header: The rule will trigger if there is any request header sent to the CDN that matches the specified header typed into the field.
HTTP Method: The rule will trigger if there is a request for the specified method. All common HTTP methods are accepted
Status Code: If the CDN receives the specified status code from the origin, the CDN will apply the rule.
Rules define the action that the StackPath EdgeRule will action once the conditions trigger.
Add Response Header: Will add a custom response header to the CDN response, as specified.
Add Header to Origin: Will add a custom Request Header to the Origin.
Cache: Will set the Cache TTL for the response to the specified TTL. The Cache-Control header will be updated to reflect this new TTL.
Do Not Cache: Will apply a no-cache rule to the specified response and will add a no-cache value to the Cache-Control header.
Never Expire: Will remove the TTL from the specified response and allow the asset to be cached indefinitely.
Redirect: Will create a permanent 301 redirection towards the specified URL.
Hide Header Will remove the specified header from the CDN response header list
Modify Header Will change the value of the specified response header when sent by the CDN
Sign URL Will set up basic URL signing for the specified request
It's possible to use wildcards, regex and globbing in your Custom EdgeRules to create patterns that match specific URLs allowing you to create a CDN configuration to your specific requirements.
Here are some examples of options for these filters:
||Only HTTP requests||http://abcdef12.stackpathcdn.com/index.html|
||Only HTTPs requests||https://abcdef12.stackpathcdn.com/index.html|
||HTTP/HTTPs request for foo.com HostName||http://foo.com/index.html, https://foo.com/static/js/anydirORfile|
||Any request for HTML files||http://abcdef12.stackpathcdn.com/index.html, https://example.com/index.html|
||Any request except TXT files||
||Any HTML file or JS files||http://abcdef12.stackpathcdn.com/index.html, https://example.com/static/js/jquery.js|
||Any request except TXT and JPG files||http://abcdef12.stackpathcdn.com/index.html, https://example.com/static/img/index.jpg|
||Any request for HTML file under Directory (recursive) "static"||http://abcdef12.stackpathcdn.com/static/index.html http://abcdef12.stackpathcdn.com/static/foo.html http://abcdef12.stackpathcdn.com/static/2/index.html http://abcdef12.stackpathcdn.com/static/2/st/index.html|
||Any request for HTML file under Directory (one level) "static"||http://abcdef12.stackpathcdn.com/static/index.html, https://abcdef12.stackpathcdn.com/static/foo.html|
||HTTP/HTTPs request for index.html under directory of Numbers||http://abcdef12.stackpathcdn.com/static/1/index.html, https://abcdef12.stackpathcdn.com/static/20/100/index.html|
Please note that if you specify the protocol in your pattern this will be ignored once the file has been cached by the CDN.
For example, pattern
http://example.com/jquery.js, then any requests to
https://example.com/jquery.js will be proxied. However, once a request to
http://example.com/jquery.js has been made,
jquery.js will be cached and a cached response will be returned for subsequent requests to
Validating and Troubleshooting EdgeRules
Most custom EdgeRules will apply an external change, such as a visible response header or redirect, which makes troubleshooting EdgeRules simple using either Curl requests in a terminal or within a browser using the network tools.
For Curls, the -I option to display headers is the most vital in verifying the rules, to check if the custom header or redirect was applied correctly. Demonstrated below is an example response from the User-Agent Redirection example. With a specified user-agent option attached to the Curl with the -A Option to specify an iPhone is trying to connect.
Browsers can also be used for verifying the behavior of a given EdgeRule. The following example is taken from a rule that just a "test" header to validate the rule has triggered. Any of the specified headers and response code based on the responses will be viewable.
Common EdgeRule Use Cases
- Adding a Canonical Header
- Excluding Content from CDN Cache
- Adding an Access-Control Header for Magento 2.x
- Redirection by User-Agent
- EdgeRule Presets
If you have any questions or would like further assistance with EdgeRules, our support team is available for 24/7 live chat.