jescalan / roots

a toolkit for rapid advanced front-end development
http://roots.netlify.com/
Other
1.45k stars 133 forks source link

Clean URLs on Amazon S3 hosting? #684

Closed dingledow closed 9 years ago

dingledow commented 9 years ago

I know clean_urls can be set in the app.coffee file to remove the .html extension when running roots watch locally. However, I need to deploy the /public directory to Amazon S3 to host the site and to have clean URLs, I would have to set the meta data of the file Content-type to text/html AND rename the file removing the .html from the end.

Is there a way that the /public compiled build could have each page created so it is an index.html file inside a directory with the name of the page. An example of this may be for a contact page:

Rather than: /public/contact.html --> /public/contact/index.html

So the browser would show exmaple.com/contact/ instead of example.com/contact.html

Any suggestions would be much appreciated.

jescalan commented 9 years ago

A quick google search found some good answers for me!

http://stackoverflow.com/questions/23463679/s3-static-pages-without-html-extension

Michaelvons commented 3 years ago

In a multipage web app with about 12 pages, manually editing the file extension and format is inefficient for on every upload.

An automated and worry-less strategy is to use AWS Lamda@Edge. It solves this completely.

First, create an AWS Lambda function and then attach your CloudFront as a trigger.

In the code section of this AWS Lamda page, add the snippet in the repository below.

https://github.com/CloudUnder/lambda-edge-nice-urls/blob/master/lambdaRewrite.js

Content delivery will still be as fast as you can blink your eyes.

PS: Note the options in the readme section of the repo above

Hope this helps!!

IvoLondon commented 2 years ago

The better approach is to use Lambda@Edge and handle the request to the correct object.

https://aws.amazon.com/it/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/

OlivierCuyp commented 1 year ago

IMHO CloudFront Functions is better suited for this kind of job than Lambda@Edge. It will most probably be cheaper and faster, here is the AWS doc & an example.