StackPath offers custom EdgeRules with every CDN Site. EdgeRules allows users toa great amount of flexibility for users 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 a Custom EdgeRules
1. Log in to the StackPath control panel.
2. Navigate to the CDN Site the EdgeRule will be created for.
3. Select the EdgeRules tab
4. Within this tab, the StackPath EdgeRules Presets and any rules created are available.
5. Select Add Custom Rule to create a new rule
6. 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.
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.