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

597
Visualizações
Nginx redirect dynamic URLs one path to another

I want to check if a parameter is present in a url in nginx and then rewrite. How can i do that?

The color is dynamic in the URLs

For e.g

  1. If url is http://website.com/lunch-box/xxxxxabc then redirect user to http://website.com/lunch-box/.

  2. If URL is http://website.com/lunch-box/xxxxxabc/ABCD123 no need to redirect. Need to load as it is.

I want to redirect if URL is matched. and xxxxxabc is dynamic text.

nginx version: nginx/1.16.1

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

# rewrite direct children of /lunch-box but not grandchildren+
rewrite  ^(/lunch-box/)[^/]+/?$  $1  last;

Walking through the regex ^(/lunch-box/)[^/]+/?$

  • ^ matches the start of a string (rewrite rules match against the path, not the full URI)
  • (/lunch-box/) matches the literal text /lunch-box/ and saves it for $1
  • [^/]+ matches one or more characters that are not a forward slash
  • /? matches zero or one forward slash
  • $ matches the end of the string

This strips off the path past what we've saved as $1, but only when that path is a direct child.

over 4 years ago · Santiago Trujillo 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