Create custom error rules
-
Log in to the Cloudflare dashboard ↗, and select your account and website.
-
Go to Rules > Overview.
-
Select Create rule > Custom Error Rule.
-
Enter a descriptive name for the rule in Rule name.
-
Under If incoming requests match, select one of the following options:
-
Custom filter expression: The rule will only apply to traffic matching a custom expression. Define the rule expression to configure which requests should be rewritten. Use either the Expression Builder or the Expression Editor to define the custom expression. For more information, refer to Edit expressions in the dashboard.
-
All incoming requests: The rule will apply to all responses with a
400
status code or above, except for block and challenge actions issued by Cloudflare’s security products.
-
-
In Deliver a custom error response, select the response type (either Custom error asset or one of the available inline responses).
If you select Custom error asset, select an existing custom error asset in Asset, or select Create new asset to create a new custom error asset.
If you select JSON response, HTML response, Text response, or XML response, enter the custom error response you want to send to web site visitors in JSON response, HTML response, Text response, or XML response, respectively. The response can include error tokens that Cloudflare will replace with real values before sending the response to the visitor. The maximum response size is 10 KB.
-
(Optional) In Response code, enter the HTTP status code of the response (an integer value between
400
and999
). If provided, this value will override the current response status code. -
(Optional) Under Place at, define where to place the rule in the rules list: first rule in the list, last rule in the list, or in a custom position (after a given rule).
-
To save and deploy your rule, select Deploy. If you are not ready to deploy your rule, select Save as Draft.
- In the Create Custom Error Asset sidebar, enter a name for the asset in Asset name.
- (Optional) Enter a description for the asset in Description.
- In URL, enter the URL of the page you want to fetch and store in Cloudflare's global network. Cloudflare will fetch all the page resources and store a minified version of the page you can use in one or more custom error rules.
- Select Save.
To review existing custom error assets, go to Rules > Settings > Custom Error Assets tab.
To configure a custom error rule via API:
- (Optional) Create a custom error asset based on a URL you provide.