我有一个用于多个单页应用程序的S3存储桶,并为此存储桶启用了静态网站托管 . Bucket有以下文件夹和文件(firstApp和secondApp是文件夹,对应不同的SPA):
firstApp
index.html
*.js & *.css files
secondApp
index.html
*.js & *.css files
我还在S3存储桶前设置了CloudFront,默认根对象设置为 index.html
. 现在 cloud-front-url/firstApp/
显示来自firstApp SPA的 index.html
而 cloud-front-url/secondApp
显示来自secondApp的 index.html
.
我需要将所有不正确的请求重定向到基于url路径的特定应用的不同 index.html
,例如如果有人请求 cloud-front-url/firstApp/non-existing-path
- 它应该从firstApp重定向到 index.html
,对于secondApp也是类似的行为 .
我知道如何设置CloudFront将所有404错误重定向到单个 index.html
:
select distribution > Error Pages > Create custom error response:
* Http error code: 404
* Error Caching Minimum TTL (seconds) : 0
* Customize response: Yes
* Response Page Path : /firstApp/index.html
* HTTP Response Code: 200
是否可以使用CloudFront根据请求的路径将404错误重定向到不同的 index.html
(在firstApp或secondApp文件夹中重定向到 index.html
)?
1 回答
在S3上托管静态网站时,不可能有不同的404页面 . 一般来说,一个桶有一个404错误页面 .
您可以将两个应用程序托管在两个独立的存储桶中 . 每个人都有自己的404错误页面 .
然后,在CloudFront中,使用指向每个单独存储桶的多个行为 . 这样,
/firstApp/
进入bucket1,/secondApp/
进入bucket2 .