Multiple Pages on a Static Website AWS S3

I am hosting a static website using AWS S3 (for convenience, ease-of-use, and because it's so cheap).

When I have multiple HTML documents. I can navigate to them using /name_of_file.html. Is there a way to route the HTML file so the URL says /name_of_file instead? I don't like the ugliness of have a .html extension in my URL and I'd rather avoid do a single page website.


Answers 1

  • As long as you upload the files with the Content-type header set to text/html, the pages would work fine if you just eliminate the .html extension off of the end when you upload them.

    Otherwise, the only option that comes to mind is to use S3 Redirects, but that only allows you to "navigate to" the pages without the .html on the end -- but you'll subsequently see the browser redirected to the .html-named file and the .html will still show up in the address bar, so that's probably not a winner.

    Alternately -- and this is quite a stretch but perhaps worth mentioning -- you could funnel the requests through an EC2 instance running HAProxy or another reverse-proxy server and rewrite (not redirect) requests not containing a dot to append '.html' to the end, but that sort of undoes the "ease of use" aspect -- although it could allow you to host a lot more sites than the 100 buckets per account limit, if you needed that, by keeping more than one "site" in a single bucket and appending a prefix to each requested object path as well. Data transfer between EC2 and S3 within the same AWS region is free, so this wouldn't incur additional bandwidth charges -- just the cost of the instance itself.

    Update (from comments):

    The AWS console may be slightly counter-intuitive since selecting Content-Type as the metadata Key then only suggests a few choices, including text/plain and text/rtf but not text/html... but the "Value" drop-down list is only offering suggestions. Anything semi-sensible will be accepted, here.

    • (in bucket) choose actions ? upload
    • click "add files"
    • select the file to upload, in the dialog box
    • click "set details" and check any applicable boxes
    • click "set permissions" and check "make everything public" (if applicable)
    • click "set metadata"
    • click "add more metadata"
    • in the "Key" drop-down list, choose "Content-Type" and then type "text/html" in the "Value" box -- it's not a choice that's offered, but this is only a list of common types and doesn't limit what you can put in the box.
    • click "start upload"

Related Articles