1

I have uploaded my HUGO static site into AWS S3 Bucket. I have also added the domain in cloudrfront.

The home index.html page works fine, but I cannot access my resources. For example https://www.example.com works fine, but I cannot access https://www.example.com/posts/. I have to redirect links to the html file every time.

On localhost https://www.example.com/posts/ displays automatically the page ( without redirecting https://www.example.com/posts/ to https://www.example.com/posts/index.html.

Is there some property in cloudfront or Amazon S3 to replicate the behaviour of localhost and not have to change the links of the site?

1
  • Please have a look at this answer and let us know if it answers your question.
    – Alexandre
    Jun 28, 2019 at 13:48

1 Answer 1

3

CloudFront does not actually have this feature. You can redirect the root object https://www.example.com/ to https://www.example.com/index.html by setting DefaultRootObject, but there's nothing for subdirectories such as https://www.example.com/posts/.

However, you can run arbitrary code on CloudFront using Lambda@Edge or CloudFront Functions, so it's possible for us to add this feature ourselves. With the "origin request" trigger we can rewrite the request to S3, changing /posts/ to /posts/index.html. https://github.com/CloudUnder/lambda-edge-nice-urls has some good handling of paths that works well with Hugo. The Amazon documentation has an example of how you can do the same thing with CloudFront Functions.

Another option is to enable uglyurls in your config so that all links within you site have index.html hardcoded in to them.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.