14

I have a set of user folders with the same folder structure, but different content, stored in S3.

/user/userA/application/folder/structure/file.xml
/user/userB/application/folder/structure/file.xml

I would like to redirect the user to a fallback folder, (with fallback content) if the s3 folder structure don't exist for that user yet.

/user-fallback/application/folder/structure/file.xml

I've tried to add a wildcard parameter to my Redirection Rules, but S3 is reading * as a literal

<RoutingRules>
    <RoutingRule>
        <Condition>
            <KeyPrefixEquals>user/*/</KeyPrefixEquals>
            <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <ReplaceKeyPrefixWith>user-fallback/</ReplaceKeyPrefixWith>
        </Redirect>
    </RoutingRule>
</RoutingRules>

So only urls starting with /user/*/ are being correctly redirected to the user-fallback folder structure.

I have more than 20 users, so creating individual RoutingRules wouldn't work either (S3 has a routing rule limit)

Any ideas?

2
  • Did you ever make progress on this?
    – Riley Lark
    Commented Mar 27, 2015 at 19:51
  • Also wondering if Amazon S3 routing rules allow any kind of wildcard?
    – evolross
    Commented Oct 9, 2015 at 1:51

2 Answers 2

3

This should work:

<RoutingRules>
    <RoutingRule>
        <Condition>
            <KeyPrefixEquals>user</KeyPrefixEquals>
            <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <ReplaceKeyPrefixWith>user-fallback/</ReplaceKeyPrefixWith>
        </Redirect>
    </RoutingRule>
</RoutingRules>
1

The Routing Rules don't allow wildcards -- but couldn't you just put a custom redirect in for any 404 errors? See example#2 here: Example 2: Redirect requests for a deleted folder to a page Just change the condition to:

<HttpErrorCodeReturnedEquals>404 </HttpErrorCodeReturnedEquals>

Would that work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.