How do you set a default root object for subdirectories for a statically hosted website on Cloudfront?

前端 未结 9 1928
[愿得一人]
[愿得一人] 2020-12-22 17:33

How do you set a default root object for subdirectories on a statically hosted website on Cloudfront? Specifically, I\'d like www.example.com/subdir/index.html

9条回答
  •  有刺的猬
    2020-12-22 18:31

    Another alternative to using lambda@edge is to use CloudFront's error pages. Set up a Custom Error Response to send all 403's to a specific file. Then add javascript to that file to append index.html to urls that end in a /. Sample code:

    if ((window.location.href.endsWith("/") && !window.location.href.endsWith(".com/"))) {
        window.location.href = window.location.href + "index.html";
    }
    else {
        document.write("");
    }
    

提交回复
热议问题