Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Cloudfront与s3。将{url}/index.html重定向到{url}/_Amazon Web Services_Amazon S3_Amazon Cloudfront - Fatal编程技术网

Amazon web services Cloudfront与s3。将{url}/index.html重定向到{url}/

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}

我使用AmazonS3存储来自AmazonCloudFront的HTTP请求。S3存储桶设置为启用网站托管。索引文档是
index.html

当我在谷歌上搜索时,我看到了以下两个URL:

  • {url}/index.html
  • {url}/
这两个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
      }]
    }
  };
}