Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks

like image 343
Alex Chumbley Avatar asked Nov 26 '13 19:11

Alex Chumbley


People also ask

Can a static website have multiple pages?

On static sites, each page is a separate HTML file. When you visit the homepage, you are viewing only the actual homepage file. Even if two pages contain a chunk of identical content like a footer, the footers exist as two separate versions.

Is this possible to run static websites from Amazon S3?

If you want to use HTTPS, you can use Amazon CloudFront to serve a static website hosted on Amazon S3. For more information, see How do I use CloudFront to serve HTTPS requests for my Amazon S3 bucket? To use HTTPS with a custom domain, see Configuring a static website using a custom domain registered with Route 53.

Which S3 feature can be used to host static website?

To enable static website hosting Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to enable static website hosting for. Choose Properties. Under Static website hosting, choose Edit.


1 Answers

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"
like image 184
Michael - sqlbot Avatar answered Sep 21 '22 03:09

Michael - sqlbot