1

I will be hosting a static web site on S3. The problem is that the web engine behind S3-as-a-web-server does not transform http://example.com/hello/ into http://example.com/hello/index.html.

When configuring the web site, there is a provision for the root document (the one which will be displayed when calling http://example.com), but not any deeper URLS (such as my example).

Is it possible to use the redirect rules to achieve that?


I actually have a solution for this problem, but is is really convoluted:

  • host the web site on an S3 bucket
  • deploy a CloudFront instance which origins in that bucket
  • use a Lambda@Edge which will rewrite the call once it hits CloudFront

I hope there is something more straightforward (I have hope in the redirect rules, though "redirect" suggests that something was already attained, which is not the case in my problem as S3 does not seem to understand what http://example.com/hello/ is.

WoJ
  • 27,165
  • 48
  • 180
  • 345

1 Answers1

0

When you specify the default index file and wants to serve index.html in a subpath, You need to have the index.html in every level.

The documentation for S3 specifies the following

If you create such a folder structure in your bucket, you must have an index document at each level. When a user specifies a URL that resembles a folder lookup, the presence or absence of a trailing slash determines the behavior of the website. For example, the following URL, with a trailing slash, returns the photos/index.html index document.

http://example-bucket.s3-website-region.amazonaws.com/photos/ However, if you exclude the trailing slash from the preceding URL, Amazon S3 first looks for an object photos in the bucket. If the photos object is not found, then it searches for an index document, photos/index.html. If that document is found, Amazon S3 returns a 302 Found message and points to the photos/ key. For subsequent requests to photos/, Amazon S3 returns photos/index.html.

Alternatively, If you want ALL paths to server index.html, this thread might be useful

srikanth Nutigattu
  • 1,077
  • 9
  • 15