2017-06-15 79 views
0

有没有可能在S3中重定向?AWS S3重定向404子错误文件夹的规则

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 

最接近的解决方案:

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

这就是它,虽然比赛应该是大小写敏感的,和(只是要迂腐)我把结尾的斜线上'美国/'以避免无意中匹配(如)'example.com/users'也有'us'(但不是'us /')作为前缀。您可能还需要根据存储桶配置测试代码403。你正在做某种SPA,我接受它(基于重写规则中的'#')? –

回答

0

假设你已经设置静态网站托管在你的水桶,你可以设置一个桶水平错误文档。

enter image description here

但是有一个警告,

当发生错误时,亚马逊S3返回一个HTML错误文档。如果您使用自定义错误文档配置了网站,则Amazon S3会返回该错误文档。但是,如果发生错误,某些浏览器会显示自己的错误消息,而忽略Amazon S3返回的错误文档。例如,当发生HTTP 404 Not Found错误时,Chrome可能会显示自己的错误,忽略Amazon S3返回的错误文档。