AWS S3 Static Website Accessible At /page.html And Not /page
I am new to AWS
and using S3
to host my static website! I have an html file, page.html
and it should be acessible at mydomain.com/page
. However, it is only accessible at mydomain.com/page.html
:(. How can I fix this?
Answer
Unfortunately if you want this to work there are a couple of solutions that you can try.
For the first by creating an index document in a subfolder i.e. /page/index.html
you would be able to access your site on /page/
. This would work well if you're using a hierarchy.
However, if you have many many pages then you will need to use another solution that can rewrite the client site URL to your .html
file.
For this you can use CloudFront with a [email protected] function to perform this in the Origin Request
stage. This function might look similar to the below.
import json
import os
def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']
filepath, extension = os.path.splitext(request['uri'])
if not extension:
new_uri = request['uri'] + '.html'
request['uri'] = new_uri
return request
By doing this your users will see a nice clean path but when it goes to your origin it will append the extension.
Related Questions
- → AWS SDK with Lumen
- → Using AWS Certificate with a parked domain for a shopify store
- → laravel or AWS don't detect my https
- → S3 putObject callback not returning expected objects
- → Amazon S3 image hosting with Shopify
- → Redirection to https not working using AWS Elastic Beanstalk
- → Shopify app showing request blocked by an extension
- → AWS Iam commands, Working correct in terminal and not working in Laravel/PHP AWS SDK
- → Violates the following Content Security Policy directive: *** in Shopify
- → AWS S3 cannot delete objects in bucket via PHP SDK
- → Laravel s3 multiple buckets
- → AWS IoT private.pem.key doesn't exist
- → Supervise queue in laravel 5.1