No internet connection
  1. Home
  2. Support

Rewriting all trailing slash links to include /index.html

By @djessee2019-11-28 11:18:38.151Z

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!

Solved in post #2, click to view
  • 6 replies
  1. Leon Stafford @leonstafford2019-11-28 11:25:24.416Z

    Hi there,

    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.

    Cheers,

    Leon

    Reply1 LikeSolution
    1. Leon Stafford @leonstafford2019-11-28 11:26:06.216Z
      1. Leon Stafford @leonstafford2019-11-28 11:26:39.959Z
    2. D
      In 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

      https://mydomain/blog/index.php/page-1/
      https://mydomain/blog/index.php/2017/09/post-1/

      Etc.? It would seem like this is something that would need to be handled as part of the static asset generation process within wp2static?

      1. 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!).

        1. D@djessee2019-11-28 18:12:51.266Z

          Thank you so much! It indeed worked like a charm. I really appreciate it!