Skip to content
Cloudflare Docs

Create custom error rules

In the dashboard

Create a custom error rule

  1. Log in to the Cloudflare dashboard, and select your account and website.

  2. Go to Rules > Overview.

  3. Select Create rule > Custom Error Rule.

  4. Enter a descriptive name for the rule in Rule name.

  5. 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.

  6. 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.

  7. (Optional) In Response code, enter the HTTP status code of the response (an integer value between 400 and 999). If provided, this value will override the current response status code.

  8. (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).

  9. To save and deploy your rule, select Deploy. If you are not ready to deploy your rule, select Save as Draft.

Create a custom error asset

  1. In the Create Custom Error Asset sidebar, enter a name for the asset in Asset name.
  2. (Optional) Enter a description for the asset in Description.
  3. 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.
  4. Select Save.

To review existing custom error assets, go to Rules > Settings > Custom Error Assets tab.

Via API

To configure a custom error rule via API:

  1. (Optional) Create a custom error asset based on a URL you provide.