2017-06-15 83 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返回的錯誤文檔。