I am trying to get an S3 bucket when it encounters a 404 rather than throwing up a 404 page it redirects to my own server so I can then do something with the error.
This is what I have cobbled together, what I think it should do is go to mydomain.com and hit the error.php and let the php script workout the filename the user was trying to access on S3.
I would like this to happen no matter what directory the request comes from. When I have an error document defined in website hosting the 404 page shows up and when I don't have a 404 page defined I get an access denied xml error.
This is my current redirection rule
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>www.mydomain.com</HostName>
<ReplaceKeyPrefixWith>error.php#!/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Can anyone give me a hint as to what I am missing please?
Change the error code:
<HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
S3 doesn't generate a 404 unless the requesting user is allowed to list the bucket. Instead, it generates a 403 ("Forbidden"), because you're not allowed to know whether the object exists or not. In this case, that's the anonymous user, and you probably don't want to allow anonymous users to list the entire contents of your bucket.
If the object you request does not exist, the error Amazon S3 returns depends on whether you also have the
s3:ListBucket
permission.If you have the
s3:ListBucket
permission on the bucket, Amazon S3 will return an HTTP status code 404 ("no such key") error.if you don’t have the
s3:ListBucket
permission, Amazon S3 will return an HTTP status code 403 ("access denied") error.— http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html
See also: Amazon S3 Redirect rule - GET data is missing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With