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 example.com/dirname
(note absence of trailing /
) to example.com/dirname/index.html
.
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
Create a header to parse and store the directory value
Create a redirect Help Guide - HTTP Redirects on the edge
For the location header you can have it be the following:
Source : "http://example.com/" req.http.X-Dirname "/index.html"
Please sign in to leave a comment.
Comments
1 comment