If you do not configure 302 redirection on your origin server, Alibaba Cloud CDN edge nodes directly return the HTTP 302 status code that is returned by your origin server to users. After you configure 302 redirection on your origin server, edge nodes process the HTTP 302 status code that is returned by your origin server. This simplifies the processing pipeline and accelerates content delivery.

Prerequisites

302 redirection is enabled on the origin server.

Background information

302 is an HTTP status code, which indicates that an existing resource is relocated and the request fails to access the resource. To address this issue, the server typically adds the Location parameter to the response header. After a client receives a response that carries the Location parameter, the request is redirected to the address specified by the Location parameter to retrieve the resource.

How it works

If an edge node redirects a request to the origin server and receives an HTTP 302 status code from the origin server, the edge node directly processes the status code. The edge node redirects to the address specified by the Location parameter returned from the origin server to retrieve the resource. In this case, the HTTP 302 status code is not returned to the client. How it works
  1. The user initiates a request to http://example.com/test.jpg.
  2. The requested file is not cached on edge nodes. The edge node redirects the request to the origin server.
  3. The origin server receives the request and returns an HTTP 302 status code. The response header carries the Location parameter, which specifies an address: http://www.example.com/test.jpg.
  4. The edge node receives the response and redirects to the address http://www.example.com/test.jpg.
  5. The edge node retrieves and caches the file.
  6. The edge node delivers the file to the user.
If other users send requests to http://example.com/test.jpg, the file is directly returned to the users because the file is already cached on edge nodes.

Procedure

  1. Log on to the Alibaba Cloud CDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column of the domain name.
  4. In the left-side domain name management pane, click Back-to-origin.
  5. On the Configurations tab, find the 302 Redirection section.
  6. Turn on 302 Redirection.
  7. Set the following parameters.
    Configure 302 redirection
    Parameter Description
    Maximum Number of Redirects
    • The maximum number of redirects

      Specifies the maximum number of times that a request can be redirected to the origin server by an edge node. Default value: 2. Minimum value: 1. Maximum value: 6.

    • Maximum number of 302 redirects = Maximum number of redirects - 1

      Specifies the maximum number of times that an edge node can redirect to the address specified by the Location parameter for each request. If the maximum value is exceeded, an HTTP 302 status code is returned to the user. Default value: 1. Minimum value: 0. Maximum value: 5.

    Retain Parameters in 302 Redirects
    • Yes: Request parameters are retained during 302 redirects. The parameter information is passed to the server specified by the Location parameter.
    • No: Request parameters are not retained during 302 redirects.
    Retain Request Headers in 302 Redirects
    • Yes: Request headers are retained during 302 redirects. The request header information is passed to the server specified by the Location parameter.
    • No: Request headers are not retained during 302 redirects.
  8. Click OK.