Tyrick
Tyrick

Reputation: 2966

S3 Static Website not handling relative links well

I have an s3 bucket with all folders and files public, and static website hosting enabled. When I visit the index page which is at https://s3-us-west-2.amazonaws.com/www.MYBUCKET.com/index.html, the page loads just fine. However, the website isn't handling relative links correctly.

The following gets sent to https://s3-us-west-2.amazonaws.com/page-2/index.html instead of https://s3-us-west-2.amazonaws.com/www.MYBUCKET.com/page-2/index.html:

<a href="/page-2/">Policy</a>

While it is true that I could probably remedy this by making href="/www.MYBUCKET.com/page-2/", but then this creates problems for local dev of the website, or deploying it anywhere outside of the www.MYBUCKET.com env.

My question is: What is going on, and how is this typically resolved?

Upvotes: 0

Views: 2079

Answers (1)

Renato Gama
Renato Gama

Reputation: 16519

You can also reach static s3 websites with the url;

http://www.MYBUCKET.com.s3-us-west-2.amazonaws.com/index.html

This should solve your problem once you remove the initial path portion. Also you can always use route53 to use own domain.

Keep in mind that you might have SSL certificate problems (but you can use http for developement)

If you really need https I recommend using CloudFront in front of your bucket, have a look at this tutorial if interested.

Upvotes: 2

Related Questions