Redirecting/Ignoring S3 index.html - amazon-web-services

Is there a way to utilize the main subfolder on S3 without the need to append the /index.html after the URL of that bucket?
For example my bucket URL is https://s3.amazonaws.com/hello/, however this shows a Access Denied error, and I need to enter /index.html to view it.
Is it possible to somehow remove the need for index.html and/or redirect it, so that my main URL will be the subfolder? EG: if I access https://s3.amazonaws.com/hello/ it works, and shows the index.html file (but without the filename, as would happen on a 'regular' Linux type server).

You can define a default page, but only if you configure the bucket for Static Website Sharing, which also results in a slightly different URL format.
The URL would look like:
<bucket-name>.s3-website-<AWS-region>.amazonaws.com/hello
See: Hosting a Static Website on Amazon S3

Related

Subdirectory pages not found static site hosted on Google Cloud Storage Bucket

I'm setting up a static site on a Google Cloud Storage Bucket with Loadbalancer. The site gets generated with Gridsome and then the dist folder gets saved in the bucket.
I have set the index and error with gsutil like in the [documentation]: https://cloud.google.com/storage/docs/gsutil/commands/web
Now I am facing a problem with how every url for accessing subdirectories gets redirected to dir/index.html. This is desired behavior, the dir/index.html page even exists in the bucket. But I still get a 404 - not found.
If I do a curl to the url subdir/index.html I get the HTML
I do not know exactly how you are testing your subfolder but I think this link can help you with your issue Error 404 when loading subfolder on GCS. In addition, you maybe must to take a look here How subdirectories work.
Based on How subdirectories work on GCS, when browser request URL http://www.example.com/dir it will be redirect (301) to The object http://www.example.com/dir/index.html on content served.
My assumption is there is no route http://www.example.com/dir/index.html on Vue (vue-router). So it will be throw to Not Found 404 page.
The simple solution is try to change all subdirectories link from
http://www.example.com/dir, http://www.example.com/about etc, to
http://www.example.com/dir/, http://www.example.com/about/
It will not redirect to 404 page when you request subdirectories url or reload the browser. But we all know that it's not best practices.

Amazon S3 redirects to /index.html not root of page

I have two sites statically hosted at S3.
Site example-one.com should redirect to example-two.com.
I added a redirect in the S3 bucket for example-one.com.
Like shown in the picture below.
Problem: entering example-one.com results in example-two.com/index.html
Question: How can I make it redirect to **example-two.com and not example-two.com/index.html ?**
When I access example-two.com directly it results in example-two.com as intended.
example-two.com has the S3 static site setting index document given as index.html
I use CloudFront for both domains. They previously had set the setting default root object as index.html, however I removed this earlier today so it's blank now.
To see it live access the link
Please specify if further details are needed :-)

How to redirect a naked URL in an AWS S3-powered web site?

I will be hosting a static web site on S3. The problem is that the web engine behind S3-as-a-web-server does not transform http://example.com/hello/ into http://example.com/hello/index.html.
When configuring the web site, there is a provision for the root document (the one which will be displayed when calling http://example.com), but not any deeper URLS (such as my example).
Is it possible to use the redirect rules to achieve that?
I actually have a solution for this problem, but is is really convoluted:
host the web site on an S3 bucket
deploy a CloudFront instance which origins in that bucket
use a Lambda#Edge which will rewrite the call once it hits CloudFront
I hope there is something more straightforward (I have hope in the redirect rules, though "redirect" suggests that something was already attained, which is not the case in my problem as S3 does not seem to understand what http://example.com/hello/ is.
When you specify the default index file and wants to serve index.html in a subpath,
You need to have the index.html in every level.
The documentation for S3 specifies the following
If you create such a folder structure in your bucket, you must have an
index document at each level. When a user specifies a URL that
resembles a folder lookup, the presence or absence of a trailing slash
determines the behavior of the website. For example, the following
URL, with a trailing slash, returns the photos/index.html index
document.
http://example-bucket.s3-website-region.amazonaws.com/photos/ However,
if you exclude the trailing slash from the preceding URL, Amazon S3
first looks for an object photos in the bucket. If the photos object
is not found, then it searches for an index document,
photos/index.html. If that document is found, Amazon S3 returns a 302
Found message and points to the photos/ key. For subsequent requests
to photos/, Amazon S3 returns photos/index.html.
Alternatively, If you want ALL paths to server index.html, this thread might be useful

AWS S3 Redirect only works on bucket as a subdomain not bucket as a directory

Many people have received 100s of links to PoCs that are on an internal facing bucket and the links are in this structure.
https://s3.amazonaws.com/bucket_name/
I added a redirect using AWS's Static website hosting section in Properties and it ONLY redirects when the domain is formatted like this:
https://bucket_name.s3-website-us-east-1.amazonaws.com
Is this a bug with S3?
For now, how do I make it redirect using both types of links? My current workaround is to add a meta redirect tag in each html file.
The s3-website is the only endpoint that supports redirects unfortunately. Using the s3.amazonaws.com supposes that you will be using S3 as a storage layer, instead of a website. If the link is to a specific object, you can place an HTML file at that url with a JS redirect, but other than that there is really no way to achieve what you are trying to do.
In the future, i would recommend always setting up a Cloudfront distribution for those kinds of usecases, as that will allow you to change the origin later on.

How to control the URL that Django generates?

How can I get Django to generate the static URL's using static.mywebsite.com, instead of static.mywebsite.com.s3.amazonaws.com?
The S3 bucket used for static files works when I am using a bucket name with no periods. But with a bucket using periods, it gives Failed to load resource: net::ERR_INSECURE_RESPONSE
The reason I am trying to use a bucket with periods is because this guide and two StackOverflow posts say that this is required to get an address of static.mywebsite.com, instead of mywebsite-static.s3.amazaonaws.com:
http://carltonbale.com/how-to-alias-a-domain-name-or-sub-domain-to-amazon-s3/
how appoint a subdomain for a s3 bucket?
Amazon S3: Static Web Sites: Custom Domain or Subdomain
And it seems to work; when I browse to static.mywebsite.com, I get an XML from S3 saying AccessDenied. In the last link above, a user comments to ask if this will work with HTTPS. It initially appears that it does not.
Upon inspection, the URL's of the static files generated by Django still use the static.mywebsite.com.s3.amazonaws.com address. If I understand correctly, this is a HTTPS certificate issue due to the periods creating additional layers of subdomains.
So, I changed the settings to use:
STATIC_URL = 'https://%s.mywebsite.%s/' % ('static', 'com')
But that resulted in it generating static.s3.amazonaws.com.
How can I get Django to generate the URL's using static.mywebsite.com?