Why is a trailing slash added to the URL when I use the Amazon S3 static website redirection feature?

2 minute read
0

I'm using Amazon Simple Storage Service (Amazon S3) static website redirection rules. Amazon S3 adds a slash at the end of the URL that breaks my website.

Short description

Note: The following resolution applies only to Amazon S3 static website endpoints. For more information, see Website endpoints.

The addition of a trailing slash to the redirected URL is an expected behavior with Amazon S3 static website hosting.

To avoid the addition of a trailing slash in the redirected URL, use the following workaround:

  1. Configure an index document to host the S3 static website.
  2. Set the website redirect location in the metadata of the object to configure the redirect.

Resolution

Configure an index document to host the static website

First, complete the following steps to specify the name of the index document, and delete the redirection rules:

  1. Open the Amazon S3 console.
  2. From the Buckets list, choose the name of your bucket.
  3. Choose Properties.
  4. Under Static website hosting, choose Edit.
  5. On the Edit Static website hosting page, for Static website hosting, choose Enable.
  6. For Hosting type, select Host a static website.
  7. For Index document, specify the name of an object that you want to use to set the redirection metadata. An example name is, index.html.
    Note: Don't begin your index name with a "/". For example, don't use: /index.html. Also, Amazon S3 object names are case sensitive.
  8. Delete the redirection rules.
  9. Choose Save changes.

Then, use the S3 console to configure the index document.

Set up the website redirection

Complete the following steps:

  1. Open the Amazon S3 console.
  2. From the Buckets list, choose the name of your bucket.
  3. Under Objects, choose your index document.
  4. Choose the Properties tab.
  5. In the Metadata section, choose Edit.
  6. Under Metadata, do the following:
    Choose Add metadata.
    For Type, select System defined.
    For Key, choose x-amz-website-redirect-location from the dropdown list.
    For Value, enter the redirect URL.
  7. Choose Save changes.

Related information

Configuring a webpage redirect

AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago
2 Comments

I have followed this procedure [carefully] several times, but still the redirected URL has a trailing slash that is unexpected, so fails.

JerryFr
replied 7 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 7 months ago