Conditionally serving different content based on header in initial backend response


I’m using Fastly in front of S3 to serve a static site. Since I’m using S3 as an origin via its REST API (for TLS between Fastly and S3) I need to setup things like courtesy redirects for (note absence of trailing /) to

My current plan is to add objects to my bucket named after each directory which contain a header giving the key of the corresponding index.html object that should be served.

This means that my Fastly/VCL config needs to check the header of the initial backend response and conditionally request and return a different object from S3.

What’s the best way to do this with Fastly configs? Do I need to setup custom VCL?


Hi Jonathan,

An option that can help with your scenario would be to do a redirect based on the header. This can be done in the app or with custom VCL.

For instance, in the app

For the location header you can have it be the following:

Source : “” req.http.X-Dirname “/index.html”