jhummel
jhummel

Reputation: 1764

Change cloudfront error response to default root object

I'm creating a single page app that is deployed to S3/cloudfront. I have several gulp tasks that are executed when deployments are read. One of these steps revs all my files so index.html becomes something like index-5737284.html. After the file is renamed gulp calls out to cloudfront and changes the default root object to match the new name. This effectively invalidates the cache in a quick/cheap way.

My problem comes in when I try to refresh a page of my application. e.g., myapp.com/some-page. Because it's a single page app, it doesn't exist. I'd like to redirect all those requests to the new default root object. Is there anyway to configure that in cloudfront? I can manually type in a redirect for 404 errors, but since I don't know what the random hash is going to be on my index I need something more automatic.

Upvotes: 1

Views: 1081

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179314

I'd like to redirect all those requests to the new default root object.

Since the default root object is accessible at /, you can just redirect all requests to /. You don't have to redirect them to the actual path of whatever the default root object happens to be.

CloudFront handles requests for the default root object by rewiting the URI internally, before sending the request to the origin.

Upvotes: 3

Related Questions