Configure custom error pages

更新时间:
复制 MD 格式

You can configure Alibaba Cloud CDN to return a custom error page when a client requests content that does not exist or an error occurs. Instead of a default error message, a CDN point of presence (POP) serves a page you specify, providing a helpful and branded user experience.

Background information

Alibaba Cloud CDN allows you to redirect users to a custom error page when a specific HTTP status code is returned.

When a client requests a resource from your web service that does not exist, the origin server typically returns a default 404 error page. To provide a better user experience, you can configure a custom error page by specifying the URL to which users are redirected when a specific HTTP or HTTPS response status code is returned.

Note

If your custom error page uses resources that are accelerated by Alibaba Cloud CDN, standard content delivery charges apply.

Supported status codes

You can configure custom error pages only for the following status codes: 400, 403, 404, 405, 414, 416, 500, 501, 502, 503, and 504.

Status code

Description

400

The request contains a syntax error.

403

The server understood the request but refuses to authorize it.

404

The server could not find the requested resource.

405

The server recognizes the request method but does not support it for the target resource.

414

The request URL is too long for the server to process.

416

The server cannot serve the requested range.

500

The server encountered an unexpected condition that prevented it from fulfilling the request.

501

The server does not support the functionality required to fulfill the request.

502

The server, while acting as a gateway or proxy, received an invalid response from an upstream server.

503

The server is temporarily unable to handle the request, often due to maintenance or overload.

504

The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server.

Procedure

  1. Log on to the CDN console.

  2. In the left navigation pane, click Domain Names.

  3. On the Domain Names page, find the target domain name and click Manage in the Actions column.

  4. In the domain's navigation pane, click Cache.

  5. Click the Custom Pages tab.

  6. Click Customize to configure the status code and URL for the custom error page.

    For example, select 404 for Error Code. The Description is automatically populated. In the Redirect Link field, enter the URL of your custom error page, such as http://example.aliyundoc.com/error404.html, and then click OK.

  7. Click OK to save the configuration.

    After you successfully configure the custom error page, you can find the entry in the Custom Pages list and click Modify or Delete to manage it.

Configuration example

To display a custom page for 404 errors, assume you have a page named error404.html in the root directory of your origin server. This page is accessible through the accelerated domain name example.aliyundoc.com. You can configure a custom error page for the 404 status code with the following settings.

  • Error Code: 404

  • Redirect Link: The URL of your custom page. For example: http://example.aliyundoc.com/error404.html.

  • Result: When a client request triggers a 404 error, the user is redirected to http://example.aliyundoc.com/error404.html.

FAQ

Avoiding redirect loops for 403 pages

When you configure a custom error page for the 403 status code, specifying a redirect URL can cause a redirect loop. To avoid this issue, use the following method:

  1. Use the Rewrite Access URL feature in the CDN console instead of setting a redirect URL in the custom error page configuration.

  2. Set the path to rewrite to / and the target path to the static error page, such as /error/403.html.

Important

Ensure that the 403 error page itself does not trigger another 403 redirect. Otherwise, a redirect loop occurs, and users cannot access the page.

API reference

BatchSetCdnDomainConfig