Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
Cloudfront redirect for S3 subdirectories

I have a S3 bucket with multiple directories /experiment1, experiment2, etc. Inside each one of these directories lives a static application with the relevant files (index.html, js bundles). Each one of these apps have their own in app SPA router to handle routing.

The routing for access these apps are relatively straightforward for the index.html, going to https://blahblah.com/experiment1/ works as expected, rendering the app. The problem is when it goes deeper than the directory root. For example, going to https://blahblah.com/experiment1/about will give a 404, because naturally that file does not exist on S3. In the past when there's only one "App" in an S3 bucket, a redirect of the 404 origin response to /index.html in Cloudfront has worked. In this case this won't work because i need to redirect dynamically to /experiment*/index.html. Below is a Lambda@Edge configuration i've tried but have not successfully gotten it to work.

Any help is appreciated

exports.handler = (event, context, callback) => {
    'use strict';
    const response = event.Records[0].cf.response;
    // grabs the experiment1 part of /experiment1/about
    const firstPath = response.uri.split('/')[1];
    
    if (response.status == 404) {
        
        //Response Status Code and Description
        response.status = 200;
        response.statusDescription = 'OK';
        
        response.body = '';
        
        //Set the Redirect Location
        response.headers['location'] = [{ key: 'Location', value: `/${firstPath}/index.html` }];
    }
    callback(null, response);
};

This config just gives me a blank page, with a status of 200

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use HTTP status code 302 to indicate a temporary redirect instead of status code 200 which indicates success.

response.status = 302;
response.statusDescription = 'Found';
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda