Skip to content

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

3 minute read
2

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.

Amazon S3 might add a trailing slash when it interprets a request as a directory-style prefix. For example, if path/index.html exists and the index document is index.html, then a request to /path can receive an intermediate redirect to /path/. This behavior is expected for Amazon S3 static website endpoints. Amazon S3 doesn't add a trailing slash when you use bucket-level redirect requests for an object. The following table shows typical outcomes of redirection methods:

MethodExample requestS3 adds "/"Typical outcome
Redirect requests for an object/pathNohttps://target/path
Routing rules with a directory index/pathYes/path/ then redirect
Redirect metadata on index object/pathYes/path then /path then https://target/path
Exact key redirect object path/pathNoSingle hop to https://target/path

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.

Note: If you use this workaround, then Amazon S3 still adds a trailing slash to the redirected URL when it interprets the request as a directory. However, the final redirect to your target URL omits the trailing slash.

Verify the results

To verify that your redirect works, submit curl requests with and without the trailing slash. Confirm that the final redirect location is accurate. For example, run the following commands:

curl -L -I http://yourdomain/path  
curl -L -I http://yourdomain/path/

Note: Replace yourdomain/path with the domain name and path for your URL.

Related information

Configuring a webpage redirect

AWS OFFICIALUpdated 14 days ago
4 Comments

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

replied 3 years ago

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

AWS
MODERATOR
replied 3 years ago

Breaking change. Used to be working for me for a few years for my <FQDN>/<path> redirects just fine. As taught by my courses teachers. Last week discovered ALL my Route53 -> S3 -> website -> redirect redirects started adding a trailing slash for some reason.

Instead of waiting for someone to introduce a proper feature switch for breaking changes like this one, just moved on. Migrated my solution to an Route53 -> CloudFront -> CloudFront Function one. So far, so good. Till something else underneath changes...

replied 7 months ago

This article was reviewed and updated on 2026-06-02.

AWS
EXPERT
replied 13 days ago