Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 Respuestas
Responde la pregunta

0

Your second rewrite condition limits the rule:

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda