The 301/302 redirection feature allows CDNDCDN to handle 301 and 302 responses from the origin server. After you enable this feature, DCDN nodes follow the redirection specified in a 301 or 302 response from the origin server. This reduces round-trip requests and accelerates resource retrieval for users.
Prerequisites
301/302 redirection is used on the origin server.
The permissions to configure 301/302 redirection have been obtained. By default, this is unavailable to external users. To request permissions, submit a ticket.
Background information
301 and 302 are HTTP status codes that indicate a resource has been moved. In this situation, a server typically includes a Location header in the response. When a client receives a 301 or 302 response with a Location header, the client sends a new request to the address specified in the Location header to retrieve the resource.
How it works
If a POP redirects a request to an origin server and receives HTTP status code 301 or 302 from the origin server, the POP processes the status code. The request is redirected to the address that is specified by the Location header returned from the origin server to retrieve the resource. In this case, HTTP status code 301 or 302 is not returned to the client.
-
A client requests the file
http://example.com/examplefile.txt. -
The file is not cached on the DCDN node. The node fetches the file from the origin server.
-
The origin server returns a 301/302 status code. The Location address is
http://www.example.org/examplefile.txt. -
The DCDN node receives the response and sends a request to the Location address
http://www.example.org/examplefile.txtto retrieve the resource. -
The DCDN node retrieves the resource and caches it on the DCDN node.
-
The DCDN node returns the resource to the client.
If other users request http://example.com/examplefile.txt, the requested file is served directly from the POP.
Usage notes
Before you configure 301/302 redirection for a domain name, check whether an origin host is configured for the domain name. For more information, see Configure the default origin host.
If an origin host is not configured for the domain name: When the origin server returns HTTP status code 301 or 302 and the Location header that specifies a URL to the POP, the request is redirected to the URL that is specified by the Location header. The value of the Host header in the request is the domain name that is specified by the Location header.
If an origin host is configured for the domain name: When the origin server returns HTTP status code 301 or 302 and the Location header that specifies a URL to the POP, the value of the Host header in the request is the Host header that is configured for the accelerated domain name. By default, the Host header value is the accelerated domain name. If you use the domain name that is specified by the Location header as the value of the Host header in the origin request, an error occurs. If you want DCDN to support this scenario, submit a ticket.
The Location header that is returned from the origin server can be in the following formats:
Location:
http://www.example.net/index.html. The POP redirects the request to the full URL specified by the Location header.Location:
//www.example.net/index.html. The POP redirects the request to the URL that includes the protocol that the original request uses and the value of the Location header.Location:
/index.html. The POP redirects the request to the URL that includes the protocol and domain name that the original request uses and the value of the Location header.
Procedure
-
Log on to the DCDN console.
-
In the left-side navigation pane, click Domain Names.
-
On the Domain Names page, find the target domain name and click Configure.
-
In the left-side navigation tree of the domain name, click Origin Fetch.
On the Origin Fetch tab, find 301/302 Redirection.
Turn on the 301/302 Redirection switch.
Click Modify and configure the parameters according to the following table.
Parameter
Description
Maximum Number of Redirects
Specify the maximum number of times that a POP can redirect to the URL that is specified by the Location header for each request. If the maximum value is exceeded, HTTP status code 301 or 302 is returned to the user. Valid values: 1 to 5. Default value: 2.
NoteThe maximum number of 301/302 redirects determines the number of origin requests that can be redirected to the origin server by a POP.
Maximum number of origin requests = Maximum number of 301/302 redirects + 1. In this case, the default maximum number of origin requests is 3. Valid values: 2 to 6.
Retention Request Parameters
Yes: In 301/302 redirects, the parameters in requests that are redirected to the origin server are retained. The request parameters are passed to the server specified by the Location header.
No: In 301/302 redirects, the parameters in requests that are redirected to the origin server are not retained.
Retain Request Headers
Yes: In 301/302 redirects, the headers in requests that are redirected to the origin server are retained. The header parameters are passed to the server specified by the Location header.
No: In 301/302 redirects, the headers in requests that are redirected to the origin server are not retained.
Click OK.