gpt4 book ai didi

amazon-web-services - Amazon S3 将 404 重定向到不同的主机

转载 作者:行者123 更新时间:2023-12-04 08:18:08 25 4
gpt4 key购买 nike

我试图在遇到 404 时获取 S3 存储桶,而不是抛出一个 404 页面,它将重定向到我自己的服务器,以便我可以对错误进行处理。

这是我拼凑起来的,我认为它应该做的是转到 mydomain.com 并点击 error.php 并让 php 脚本运行用户试图在 S3 上访问的文件名。

无论请求来自哪个目录,我都希望这种情况发生。当我在托管 404 页面的网站中定义了错误文档时,当我没有定义 404 页面时,我会收到访问被拒绝的 xml 错误。

这是我当前的重定向规则

 <RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>www.mydomain.com</HostName>
<ReplaceKeyPrefixWith>error.php#!/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>

任何人都可以给我一个关于我缺少什么的提示吗?

最佳答案

更改错误代码:

<HttpErrorCodeReturnedEquals>403</HttpErrorCodeReturnedEquals>
除非允许请求用户列出存储桶,否则 S3 不会生成 404。相反,它会生成 403(“禁止”),因为您无法知道对象是否存在。在这种情况下,这是匿名用户,您可能不希望匿名用户列出您的存储桶的全部内容。

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


另见: Amazon S3 Redirect rule - GET data is missing

关于amazon-web-services - Amazon S3 将 404 重定向到不同的主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28115048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com