After you configure 302 redirection on your origin server, edge nodes process the HTTP 302 status code that is returned by your origin server instead of returning the status code to clients. This simplifies the request 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 HTTP 302 status code and 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 sends a request to http://example.com/examplefile.txt.
  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.org/examplefile.txt.
  4. The edge node receives the response and redirects to the address http://www.example.org/examplefile.txt.
  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/examplefile.txt, 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 management pane of the domain name, 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 request parameters are 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 parameters are passed to the server specified by the Location parameter.
    • No: Request headers are not retained during 302 redirects.
  8. Click OK.

Configuration examples

Sample scenario: The origin server relocated to another domain name. You want users to visit the origin server through the original domain name so that you do not need to make user-facing changes.

Configuration: Enable 302 redirection for the domain name example.com. The following figure shows the configuration.Configuration
Expected result: Users request the file http://example.com/examplefile.txt, which is not cached on edge nodes. The edge nodes redirect the requests to the origin server with the original request parameters and headers retained. The origin server receives the requests and returns the HTTP 302 status code and the URL of the file http://www.example.org/examplefile.txt to the edge nodes.
  1. The edge nodes receive the HTTP 302 status code and redirect to the URL provided by the origin server. The redirection is performed only one time for each request. If the redirection fails, the HTTP 302 status code is returned to the users.
  2. The edge nodes retrieve the requested file, return it to the user, and cache it.
  3. Other users can retrieve the file http://example.com/examplefile.txt directly from the edge nodes.