1 Answer
- Newest
- Most votes
- Most comments
0
Hi
The issue you're facing is that refreshing the page or pasting the URL into a new window results in CloudFront potentially serving the object directly from its cache, bypassing your CloudFront function and the logic to rewrite the URI to the root index.html. Here's how to address this:
1. Leverage CloudFront Behaviors with Cache Key and Minimum TTL:
Refer repost: https://repost.aws/knowledge-center/prevent-cloudfront-from-caching-files
- Create a separate CloudFront behavior specifically for your root domain (e.g., my-domain.com).
- In this behavior configuration:Set "Cache Policy" to "Caching Disabled". This ensures CloudFront always fetches the latest version from S3.
- Set "Minimum TTL" to a low value (e.g., 0 seconds).
- Keep the existing behavior with the CloudFront function for handling subdomains.
2. Utlizie cache control headers
https://repost.aws/knowledge-center/cloudfront-cache-content
Relevant content
- Accepted Answerasked 2 years ago
- asked 5 years ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 8 months ago
thanks for answering GK,
I already have Caching Disable for Default(*), but i have added what you recommended and now i have this
and since i'm using Managed-CachingDisabled, TTL is already set to 0
This did not help... when i refresh i still see the root index By the way, the url after refresh is
subdomain.domain.com/some/url/here
Hi Look for the line request.uri = '/' + subdomain[0] + request.uri;. This line should be responsible for rewriting the URI for subdomains.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/test-function.html