Skip to main content
A 301 or 302 from the CDN can be generated by the CDN or by the origin. Check CDN-generated redirects first. If those settings are not producing the 301 or 302, compare a CDN request with a request that matches the origin pull.

CDN-generated redirects

The CDN can return 301 or 302 without the origin issuing that status. Check these settings on the resource OPTIONS tab before comparing origin pulls.
  • Redirect HTTP to HTTPS in Access. An HTTP request to the CDN hostname returns 301 or 302 to HTTPS when Enable redirect HTTP to HTTPS is on.
  • Rewrite with the redirect (302) or permanent (301) flag, including the same option on a CDN rule that matches the path.
If the CDN request returns 301 or 302 and a matching origin request returns 200, the redirect is CDN-generated. Adjust that setting or rule instead of origin pull settings.

Origin pull comparison

Use GET and discard the body, because curl -I sends HEAD, which an origin application can handle differently from GET. The hostname in --resolve and in the URL must match the configured SNI hostname. The -H "Host: …" value must match Custom Host header. Those values can differ when Custom SNI hostname is selected.
Replace cdn.example.com with the CDN hostname. Replace sni.example.com with the SNI hostname: the Change Host header value when Dynamic SNI hostname is selected, or the Specify SNI hostname value when Custom SNI hostname is selected. Replace host.example.com with Custom Host header. Replace 203.0.113.10 with the origin IP. --resolve pins the request to that IP while keeping the SNI hostname in the URL. A request to the origin hostname alone does not reproduce the CDN pull when the origin uses an IP address, virtual hosting, authentication, or a different Host or TLS server name. Add the same authentication headers or credentials the CDN sends when the origin requires them. If both responses return 301 or 302 to the same Location, the origin is redirecting the pull. Then match Origin pull protocol, Change Host header, origin source, and Redirection from origin in the Gcore Customer Portal.

Origin pull protocol

Origin pull protocol is in the General section of the CDN resource OPTIONS tab. Match HTTP, HTTPS, or HTTP and HTTPS to origin redirects in origin settings.
  • Select HTTPS when the origin redirects HTTP requests to HTTPS.
  • Select HTTP when the origin redirects HTTPS requests to HTTP.
  • Select HTTP and HTTPS only when the origin serves both protocols without a redirect. With this value, the CDN uses the protocol from the client request, so an origin that still redirects one protocol will keep returning 301 or 302.

Change Host header

Change Host header is in HTTP headers on the OPTIONS tab. The Host header sent to the origin usually matches the origin hostname and does not update automatically when the origin changes. If the origin hostname changes, update Custom Host header to the new hostname. Leave Forward Host header off unless the origin must receive the same Host header that the client sent to the CDN.

Origin source after a redirect

If the origin redirects one hostname to another, set the destination hostname in the Origin group. When domain.com redirects to www.domain.com, use www.domain.com as the origin and set Custom Host header to www.domain.com. Leaving the origin on the hostname that issues the redirect keeps the origin returning 301 or 302. By default, the CDN caches and serves that redirect to clients.

Redirection from origin

Redirection from origin is in the Cache section of the OPTIONS tab. By default, the option is off, so when the origin returns 301 or 302 the CDN caches that response and serves it to the client. When Follow redirect from origin is on and 301 or 302 is selected, the CDN retrieves the target content, caches it, and returns that content instead. Configuration is in the Redirection from origin article. Enable Follow redirect from origin when the CDN should fetch the redirected object. Change protocol, Host header, or origin source instead when the origin should return the object without a redirect. After changing the protocol, Host header, origin, or redirect behavior, click Save changes, purge the affected URL, then retest. 301 and 302 responses can be cached, so a stale redirect can persist until purge.

Response codes in Statistics

The Response codes report shows how many CDN responses are 301 or 302 compared with 200.
1

Open Statistics

In the Customer Portal, navigate to CDN > Reports > Statistics.
2

Select the resource

In CDN resource, select the resource.
3

Choose Response codes

Select the Response codes report. Check the share of 301 and 302 compared with 200. A large or persistent redirect share means the origin is still issuing 301 or 302 on the pull.
After a protocol, Host header, origin, or redirect change, Log viewer lists recent requests to the resource, including status code. Filter on 301 or 302 to confirm whether the redirect is still occurring. Logs uploader is a paid option for the same status codes over a longer window. Contact the account manager or Gcore Support to activate it.

Successful pull after the change

Request the CDN URL again with GET and discard the body:
A 200 (or another non-redirect success) means the client is no longer receiving a 301 or 302 from the CDN. If 301 or 302 remains, repeat the CDN-generated check and the origin comparison, then check Location.