Alibaba Cloud CDN allows you to rewrite HTTP headers in HTTP response messages returned from an origin server. You can add, delete, change, and replace HTTP response headers based on your business requirements.
Background information
HTTP response headers are a component of the header section in response messages transmitted over HTTP. HTTP response headers bring specific parameters to clients.
If the requested resource is not cached on CDN nodes, the request is redirected to the origin server. Then, the origin server returns the requested resource to the CDN node. Alibaba Cloud CDN allows you to rewrite HTTP response headers from origin servers so that clients can identify response information more easily. For example, you can rewrite the value of the Content-Type header before it is returned to clients to ensure that the clients can parse the content retrieved from the origin server. If Content-Type is set to an invalid value, garbled text appears. In this case, the value of Content-Type must be rewritten on CDN nodes.

- After an origin server receives a request from a CDN edge node, the origin server returns an HTTP message to the CDN edge node. A rewrite rule rewrites only HTTP headers in responses that are returned from an origin server. It does not rewrite HTTP headers in responses that are returned from CDN edge nodes to clients.
- You cannot configure custom HTTP response headers for wildcard domain names.
Procedure
Log on to the ApsaraVideo VOD console.
In the left-side navigation pane, choose Configuration Management > CDN Configuration > Domain Names. The Domain Names page appears.
On the Domain Names page, find the domain name that you want to manage and click Configure in the Actions column.
In the left-side navigation pane of the specified domain name, click Back-to-Origin.
Click the Origin HTTP Response Headers tab.
Click Add and configure the parameters.
Important If different operations are performed on the same response header at the same time, these operations have different priorities. The operations are prioritized in the following descending order: Replace > Add > Change or Delete. For example, if you perform the Add and Delete operations on the same request header at the same time, the request header is added and then deleted.- Parameters of the Add operation

Parameter Example Description Operation Add Adds a response header to response messages from an origin server. Response Header Custom Cache Response Headers You can use the default value, or select Custom Cache Response Headers from the Response Header drop-down list to specify a response header.
Header Name x-code The name of the custom response header is x-code.
Header Value key1 You can specify one or more values for a response header. Separate values with commas (,).
key1,key2 Allow Duplicates Allow Duplicates - Yes: You can add duplicate response headers. For example,
x-code:key1andx-code:key2can coexist. - No: The latest header value overwrites the existing one that uses the same header name. For example, if you add
x-code:key1and then addx-code:key2, the final header key-value pair isx-code:key2.
- Yes: You can add duplicate response headers. For example,
- Delete operation

Parameter Example Description Operation Delete Deletes all response headers that match the values of the Response Header and Header Name parameters. Duplicate response headers are also deleted. Response Header Custom Cache Response Headers You can use the default value, or select Custom Cache Response Headers from the Response Header drop-down list to specify a response header.
Header Name x-code The name of the custom response header is x-code.
- Parameters of the Change operation

Parameter Example Description Operation Change You can perform the Change operation only if no duplicate response headers exist. Response Header Custom Cache Response Headers You can use the default value, or select Custom Cache Response Headers from the Response Header drop-down list to specify a response header.
Header Name x-code The name of the custom response header is x-code.
Change Value To key1,key3 You can specify one or more values for a response header. Separate values with commas (,).
- Parameters of the Replace operation

Parameter Example Description Operation Replace You can perform the Replace operation only if no duplicate response headers exist. Response Header Custom Cache Response Headers You can use the default value, or select Custom Cache Response Headers from the Response Header drop-down list to specify a response header.
Header Name x-code The name of the custom response header is x-code.
Find key Allows you to use regular expressions to search for the value that you want to replace. Replace With abc Allows you to use regular expressions to replace matching values. Match Match All - Match All: All matching values are replaced. For example, if you use a regular expression to replace all the "key" in
x-code:key1,key2,key3with "abc", the key-value pair is changed tox-code:abc1,abc2,abc3. - Match the First Only: Only the first matching value is replaced. For example, if you use a regular expression to replace the first "key" in
x-code:key1,key2,key3with "abc", the key-value pair is changed tox-code:abc1,key2,key3.
- Match All: All matching values are replaced. For example, if you use a regular expression to replace all the "key" in
- Parameters of the Add operation
Click OK.
Configuration examples
Example 1
Sample scenario: Adds a response header to specify that the content returned to users is of a specified MIME type.

Expected result: The origin server adds the Content-Type header whose value is text/html to the response returned to CDN edge nodes. If the configuration is updated, the value is overwritten.
Example 2
Sample scenario:Deletes a response header from responses.
