如何解决带有 S3 存储桶的 CloudFront - 静态 HTML 网站,点击子目录从根目录返回 index.html
我有一个静态 HTML 网站,托管在具有 CloudFront 配置的 AWS s3 上。
网站有子目录:
example.com/info
example.com/product
它们包括 index.html 文件。
每当我直接点击像:example.com/info 这样的 URL 时,就会提供主要的 index.html。
知道如何解决这个问题吗?
CloudFront 配置:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
AllowedMethods:
- "HEAD"
- "GET"
- "OPTIONS"
CachedMethods:
- "HEAD"
- "GET"
Compress: true
ForwardedValues:
Cookies:
Forward: "none"
QueryString: false
Headers:
- "Access-Control-Request-Headers"
- "Access-Control-Request-Method"
- "Access-Control-Allow-Origin"
- "Origin"
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 0
SmoothStreaming: false
TargetOriginId: xxxxxx
ViewerProtocolPolicy: "redirect-to-https"
DefaultRootObject: index.html
CustomErrorResponses:
- ErrorCode: 403
ResponsePagePath: "/index.html"
ResponseCode: "200"
ErrorCachingMinTTL: 300
- ErrorCode: 404
ResponsePagePath: "/index.html"
ResponseCode: "200"
ErrorCachingMinTTL: 300
Origins:
- DomainName: !Sub "${xxxxxx}.s3.amazonaws.com"
Id: !Sub xxxxxxx
S3OriginConfig:
OriginAccessIdentity: xxxxxxxx
ViewerCertificate:
AcmCertificateArn: xxxxxxxx
MinimumProtocolVersion: "TLSv1.1_2016"
SslSupportMethod: "sni-only"
Restrictions:
GeoRestriction:
RestrictionType: "none"
HttpVersion: "http2"
IPV6Enabled: true
我的 s3 存储桶是一个静态网站:
Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
- HEAD
AllowedOrigins:
- "*"
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。