尝试找到一种方法将流量从我的 AWS CloudFront 页面重定向到另一个 URL。
我目前正在使用 Cloudfront Functions 设置“函数”。
函数代码(函数名称= exampleFunction):
function handler(event) {
var redirectUrl = "https://example.com"
var response = {
statusCode: 302,
statusDescription: 'Found',
headers: {
'Location': { value: redirectUrl }
}
};
return response;
}
我发布该内容,然后在我的 Cloudfront 分发行为上创建一个行为:
- Path Pattern: /to/my/page.html
- Origin and origin groups: example-origin-on-aws
- Compress objects automatically: No
- Viewer protocol Policy: Http and Https
- Allowed HTTP methods: GET, HEAD
- Restrict viewer access: No
- Cache key and origin requests: Cache policy and origin request policy
- Function asssociations:
- Viewer request:
- Function type: CloudFront Functions
- Function ARN / Name: exampleFunction
然后我保存更改。
我还有以下原点设置:
- Origin domain: BucketName
- Name: BucketName
- S3 bucket access:
- Yes use OAI:
- Origin access identity: My OAI
- Bucket policy: Yes
- Enable Origin Sheild: No
然后,当我尝试导航到“https://s3.amazonaws.com/BucketName/to/my/page.html”时,它仍然会将我带到该页面,而不是将我重定向到“https://example.com” 。
任何能指出我正确方向或我做错了什么的建议将不胜感激。