Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Index Document Support

An index document is a webpage that is returned when a request is made to the root of a website or any subfolder. For example, if a user enters http://www.example.com in the browser, the server returns http://www.example.com/index.html, where index.html is the default webpage of the website. Thus, your customers don't have to remember the exact URL to navigate to use for retrieving the default web page. When hosting your website on Amazon S3, you provide this index document name as part of configuring your bucket as a website, and an object with this name must exist in your bucket. The trailing slash at the root-level URL is optional. For example, if you configure your website with index.html as the index document, either of the following two URLs return the index.html index document at the root of your website.

http://example-bucket.s3-website-region.amazonaws.com/
http://example-bucket.s3-website-region.amazonaws.com

Index Documents and Folders

Objects stored in Amazon S3 are stored within a flat container, i.e., an Amazon S3 bucket, and it does not provide any hierarchical organization, similar to a file system's. However, you can create a logical hierarchy using object key names and use these names to infer logical folders that contain these objects. For example, consider a bucket with three objects and the following key names.

sample1.jpg

photos/2006/Jan/sample2.jpg

photos/2006/Feb/sample3.jpg

All three objects are stored within a bucket, with no physical hierarchical organization. However, you can infer the following logical folder structure from the key names.

sample1.jpg object is at the root of the bucket

sample2.jpg object is in the photos/2006/Jan subfolder, and

sample3.jpg object is in photos/2006/Feb subfolder.

The AWS Management Console also supports the concept of folders, by using the same key naming convention used in the preceding sample. The following console screenshot shows an ExampleBucket with a photos folder. You can upload objects to the bucket or to the photos folder within the bucket. If you add the object sample.jpg to the bucket, the key name is sample.jpg. If you upload the object to the photos folder, the object key name is photos/sample.jpg.

If your keys follow the same naming convention described above, then Amazon S3 will return the content for your index document whenever it infers that your request is for a subfolder. You should have the index document at each level of your key’s hierarchy. 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 endpoint. 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 found, Amazon S3 returns a 302 Found message and points to the photos/ key. For subsequent requests to photos/, Amazon S3 returns the photos/index.html content. If the index document is also not found, Amazon S3 returns an error.