I'm hosting my static WP site in an S3 bucket with a CloudFront distribution. I currently have to use a semi-expensive Lambda@Edge function to redirect requests to links to posts and pages within my blog that end in a '/' to force '/index.html' instead. Is there a way to specify some kind of URL rewrite rule to take care of (at least most of) these for me? Thanks for your help!
- 6 replies
- Leon Stafford @leonstafford2019-11-28 11:25:24.416Z
This is a common gotcha with CloudFront + S3 but very solvable!
When creating the S3 origin for your CloudFront distribution, use the full address to the static website (from the S3 Properties > Static Website box), not the S3 bucket address that CloudFront allows you to choose from a list when entering.
Please let me know if you need more screenshots of where to find these settings.
- DIn reply todjessee⬆:@djessee2019-11-28 11:43:50.180Z
Thanks for the quick reply! As I understand it, this approach would work for the root, but will it address all the links to posts in the format
Etc.? It would seem like this is something that would need to be handled as part of the static asset generation process within wp2static?
- Leon Stafford @leonstafford2019-11-28 15:32:04.361Z
It will work for all paths. When using the s3's static website URL, there is no need to specify the default root in CloudFront.
I've actually just moved https://wp2static.com to S3 + CloudFront this morning, off of Netlify, as the speeds are a lot better on CF. Working totally fine (and fast!).