By default, when a CDN node receives a 302 redirect response, it caches that redirect response for the requested URL — not the target page the redirect points to. Subsequent requests for the same URL are served the cached redirect, so different clients (such as desktop browsers and mobile devices) all receive the same cached content rather than device-specific pages from the origin.
To serve adaptive content through CDN while still benefiting from caching, use one of the following approaches.
Option 1: Prevent caching of the 302 response via origin server headers
Add one of the following headers to the origin server's response for the redirecting URL. This tells CDN not to cache the 302 response, so each client follows the redirect to the origin and receives device-appropriate content.
| Header | Value |
|---|---|
Cache-Control | no-cache |
Cache-Control | no-store |
Cache-Control | private |
Cache-Control | s-maxage=0 |
Cache-Control | max-age=0 |
Pragma | no-cache |
Origin server cache headers take priority over CDN cache rules. Setting any of the headers above on the redirect response overrides CDN caching policies for that URL.
After CDN stops caching the 302 response, each client follows the redirect to the origin and receives device-specific content. Subsequent requests from the same device type can still be served from cache if the redirect target is cached.
Option 2: Configure CDN cache rules to cache the redirect target
In the Alibaba Cloud CDN console, configure cache rules based on directories or file extensions so that CDN caches the redirect target content rather than the 302 response. Adjust the cached object types and cache rule priorities to match your website's directory structure.
This lets CDN accelerate delivery for each device type while bypassing the redirect for cached requests.