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

208
Visualizações
dispatcher regex match case then change parts of url to lower case

Say I have a product page /GB/en/cat/product/abc/cde/*** is a good valided 200 page,
But people could accidently type /GB/en/cat/Product/abc/cde/*** or /GB/en/cat/PRODUCT/abc/cde/*** (as my content page is case sensitive) these two url causing problem for my seo purpose So I need to have rewrite rule in dispatcher to handle anything like /GB/en/cat/Product/abc/cde/*** or /GB/en/cat/PRODUCT/abc/cde/*** ,transfer them to /GB/en/cat/product/abc/cde/***

Below is my current try out, but it only works when user types in /gb/en/cat/Product/... or /gb/en/cat/PRODUCT/... then it can successfully change to /GB/en/cat/PRODUCT/abc/cde/***

RewriteCond %{ENV:PAGE_REQUEST} ^true$
  RewriteCond %{REQUEST_URI} !^/[A-Z]{2}/[a-z]{2}
  RewriteRule ^/([a-zA-Z]{2})/([a-zA-Z]{2})(.*) "/${toupper:$1}/${tolower:$2}/${tolower:$3}" [R=301,L]

If user types in /GB/en/cat/PRODUCT/... the rewrite rule won't work... Any code suggestions would be really apprecaited. Thanks

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

0

Your second rewrite condition limits the rule:

RewriteCond %{REQUEST_URI} !^/[A-Z]{2}/[a-z]{2}
over 4 years ago · Santiago Trujillo Relatório

0

As Vlad said: your second condition will limit the rule, only if both conditions are met, the rule will be applied. Your second condition says to only apply the rule if the URI does not start with two upper case characters, followed by two lower case characters. So /GB/en/cat/PRODUCT/... won't match since the second condition is not met. This means that the rule is not applied and the upper case PRODUCT is not fixed. You can just remove this second condition since your rule won't change the correct cased characters.

As also already said by rakhi4110, your third group in your rewriterule: (.*) will include the / after the two letters of the language, so if you end the rule with /${tolower:$3}, you will end up with two slashes in the URI, to fix that you can either remove the slash at the end, or add one in between groups 2 and 3:

RewriteRule ^/([a-zA-Z]{2})/([a-zA-Z]{2})/(.*) "/${toupper:$1}/${tolower:$2}/${tolower:$3}" [R=301,L]

or

RewriteRule ^/([a-zA-Z]{2})/([a-zA-Z]{2})(.*) "/${toupper:$1}/${tolower:$2}${tolower:$3}" [R=301,L]

(IMO the first one is cleaner code)

So to conclude, the following should work:

RewriteCond %{ENV:PAGE_REQUEST} ^true$
RewriteRule ^/([a-zA-Z]{2})/([a-zA-Z]{2})/(.*) "/${toupper:$1}/${tolower:$2}/${tolower:$3}" [R=301,L]
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