Amazon web services Cloudfront与s3。将{url}/index.html重定向到{url}/
我使用AmazonS3存储来自AmazonCloudFront的HTTP请求。S3存储桶设置为启用网站托管。索引文档是Amazon web services Cloudfront与s3。将{url}/index.html重定向到{url}/,amazon-web-services,amazon-s3,amazon-cloudfront,Amazon Web Services,Amazon S3,Amazon Cloudfront,我使用AmazonS3存储来自AmazonCloudFront的HTTP请求。S3存储桶设置为启用网站托管。索引文档是index.html 当我在谷歌上搜索时,我看到了以下两个URL: {url}/index.html {url}/ 这两个URL提供相同的内容 如何设置它,使{url}/index.html执行永久移动到{url}/的代码301?理想情况下,如果它是静态内容,则不需要按照您要求的方式重定向 您可以这样配置:如果用户请求{url}/然后重定向CloudFront以服务{url}
index.html
当我在谷歌上搜索时,我看到了以下两个URL:
{url}/index.html
{url}/
如何设置它,使
{url}/index.html
执行永久移动到{url}/
的代码301?理想情况下,如果它是静态内容,则不需要按照您要求的方式重定向
您可以这样配置:如果用户请求{url}/然后重定向CloudFront以服务{url}/index.html,但不能以其他方式
参考:两个选项,复杂程度不同: 标准链接 使用
标记告诉Google给定文档的规范URL是什么:
<link rel="canonical" href="https://example.com/">
exports.handler = (event, context, callback) => {
const { request } = event.Records[0].cf;
const isIndex = request.uri.endsWith('/index.html');
if (isIndex) {
const withoutIndex = request.uri.replace(/\/index\.html$/, '');
callback(null, redirect(withoutIndex));
} else
callback(null, request);
};
function redirect(url) {
return {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
key: 'Location',
value: url
}]
}
};
}