Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Cloudfront with s3. redirect {url}/index.html to {url}/

I am serving HTTP request from Amazon CloudFront using Amazon S3 to store the file. The S3 bucket is set as Website Hosting enabled. The index document is index.html.

When I search on Google, I see both these URLs:

  • {url}/index.html
  • {url}/

Both of these URLs serve the same content.

How can I set it up such that {url}/index.html performs a code 301 Moved Permanently to {url}/?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Two options, with different levels of complexity:

Canonical URL

Use a <link> tag to tell Google what's the canonical URL for a given document:

<link rel="canonical" href="https://example.com/">

Redirect using Lambda@Edge

You can use a simple Lambda function deployed to CloudFront's edge servers. Follow this tutorial, and the function body you want (Node.js 8.10) is:

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
      }]
    }
  };
}
about 4 years ago · Santiago Trujillo Report

0

Ideally if it is static content there is no redirect need the way you asked...

You could have config in such a way that if user requests for {url}/ then redirect cloud front to serve {url}/index.html but not other way...

Ref: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!