Amazon S3 redirects 404 to another host

I try to get the S3 bucket when it encounters 404, and does not throw the 404 page, redirects it to my own server, so I can do something with an error.

This is what I put together, I think it needs to be done, go to mydomain.com and click on the error.php file and run the php script workout the name of the file that the user was trying to access on S3.

I would like this to happen no matter in which folder the request is requested. When I have an error document defined on a web hosting page 404 appears, and when I do not have a specific page on 404, I get an access denied 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 someone give me a hint about what I will miss, please?

+5
source share
1 answer

Change the error code:

 <HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals> 

S3 does not generate 404 if the requesting user is not allowed to list the bucket. Instead, it generates 403 (Forbidden) because you are not allowed to know if this object exists or not. In this case, this is an anonymous user, and you probably do not want to allow anonymous users to list the entire contents of your bucket.

If the requested object does not exist, the error returned by Amazon S3 depends on whether you have s3:ListBucket .

If you have s3:ListBucket on the bucket, Amazon S3 will return an HTTP 404 status code (β€œno such key”).

if you do not have s3:ListBucket , Amazon S3 will return an HTTP 403 status code ("denied access").

- http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html

See also: Amazon S3 Redirection Rule - Missing GET Data

+10
source

Source: https://habr.com/ru/post/1211776/


All Articles