CloudFront's "Origin Path" does not work with S3 Static Website's 302 redirects

0

I have an S3 bucket with static website hosting with the following file:

production/pages/index.html

I have created a CloudFront distribution pointing to this bucket, with the Origin Path set to "/production". When navigating to xxx.cloudfront.net/pages/ I can correctly see my index.html file.

When navigating to xxx.cloudfront.net/pages (without the trailing slash), the S3 static site hosting sends a 302 redirect to xxx.cloudfront.net/production/pages/, which ignores the Origin Path and returns a 404.

How can I make my system work to be able to have the redirection to xxx.cloudfront.net/pages/ instead?

1개 답변
0
수락된 답변

I was able to solve it by having the following redirection on my S3 static website. Not the best solution because this causes 2 redirections, but it works.

[
    {
        "Condition": {
            "KeyPrefixEquals": "production/production/"
        },
        "Redirect": {
            "HostName": "mydomain.com",
            "HttpRedirectCode": "302",
            "Protocol": "https",
            "ReplaceKeyPrefixWith": ""
        }
    }
]
Adrien
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠