4

On clicking/refresh following site https://rrc6k2ykxxxxx.cloudfront.net/example-1

this error comes for all non home page url I have reactjs App on s3 bucket which is served through cloudfront.

Error: NoSuchKey The specified key does not exist. Key: example-1

what would be best way to redirect refresh on non home pages back to home page? thanks

2 Answers 2

10

Assuming this is a single page app (SPA) since this is react - in other words, there is no file in your s3 bucket example-1/index.html?

For single-page apps, whatever is delivering the static contents needs to return the root index.html file for all unmatched paths. In CloudFront, you can click on the distribution, then click on "Error pages", click "Create a custom error response", select 404 for the HTTP error code, select "create a custom error response" and put /index.html in the response page path with a 200 for the response code. You will want to repeat this for a 403 error code.

1
  • Thanks, had to edit cloudfront and that fixed it Commented Sep 10, 2022 at 4:53
1

Just set the Error Page to index.html it will solve the problem. path => Go to aws s3 then in buckets select properties tab and go to Static website hosting Static website hosting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.