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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With