title: Subfolder redirect issue with static website hosting using S3, CloudFront and Origin Path
body: <p>I'm having some difficulties setting up static website hosting using Amazon S3 and Cloudfront.</p>
  
  <p>We have many websites that we would like to serve as static websites using Amazon S3 + Cloudfront and we would prefer to host them all in a single S3 bucket.</p>
  
  <p>Initial setup is pretty straight forward but we are having issues with sub-folder redirects if omitting trailing slash in the URL.</p>
  
  <p><strong>example, setting up a single website from the bucket:</strong></p>
  
  <p>bucket contents for website1:</p>
  
  <p>s3://bucket-name/websites/website1/index.html</p>
  
  <p>s3://bucket-name/websites/website1/about/index.html</p>
  
  <p>I have enabled static website hosting for this bucket with default document set to 'index.html'</p>
  
  <p>I have created a Cloudfront web distribution to serve this single website, default root object is set to 'index.html'.</p>
  
  <p>The distribution has a custom origin pointing to the static website url 'bucket-name.s3-website-us-east-1.amazonaws.com' with Origin Path set to '/websites/website1'</p>
  
  <p>When navigating to the distribution url '<a href="http://example.cloudfront.net" rel="noreferrer">http://example.cloudfront.net</a>' it correctly serves the 'index.html' document from 's3://bucket-name/websites/website1/index.html'</p>
  
  <p>When navigating to '<a href="http://example.cloudfront.net/about/" rel="noreferrer">http://example.cloudfront.net/about/</a>' it also correctly serves the 'index.html' document from 's3://bucket-name/websites/website1/about/index.html'</p>
  
  <p>But, if I omit the trailing slash like '<a href="http://example.cloudfront.net/about" rel="noreferrer">http://example.cloudfront.net/about</a>' S3 redirects me to '<a href="http://example.cloudfront.net/websites/website1/about/" rel="noreferrer">http://example.cloudfront.net/websites/website1/about/</a>', since I have Origin Path set to '/websites/website1' Cloudfront will request index.html from 's3://bucket-name/websites/website1/about/websites/website1/about/index.html' which does not exist.</p>
  
  <p>Am I missing something here? Is this an impossible setup using only Cloudfront and S3?</p>