AWS S3 redirect rules for subfolders with 404 error

时间:2017-06-15 09:25:53

标签: amazon-web-services amazon-s3 http-status-code-404

Is there any possibility to make redirects in S3 like this?

domain/us/wrongurl.html redirect to this ➜ domain/us/404.html
domain/uk/wrongurl.html redirect to this ➜ domain/uk/404.html
domain/wrongurl.html redirect to this ➜ domain/404.html

The closest solution:

<RoutingRules>
    <RoutingRule>
        <Condition>
            <KeyPrefixEquals>US</KeyPrefixEquals>
            <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <HostName>domain.name</HostName>
            <ReplaceKeyPrefixWith>US/404.html#</ReplaceKeyPrefixWith>
        </Redirect>
    </RoutingRule>
</RoutingRules>

1 个答案:

答案 0 :(得分:0)

Assuming that you have setup static web hosting on your bucket, you can set up a bucket level error document.

enter image description here

But there is a caveat,

When an error occurs, Amazon S3 returns an HTML error document. If you have configured your website with a custom error document, Amazon S3 returns that error document. However, when an error occurs, some browsers display their own error message, ignoring the error document Amazon S3 returns. For example, when an HTTP 404 Not Found error occurs, Chrome might display its own error ignoring the error document that Amazon S3 returns.