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

185
Vistas
Apache rewrite condition for matching Query

I need a rewrite condition for returning e.g. 403, when a query contains characters, which are not in my "whitelisted" character class. The query beginns with q= So my attempt was:

RewriteCond %{REQUEST_URI} ^/generic/
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} q=[^a-z]+
RewriteRule .* - [F]

It is working almost. Only problem is, when the query beginns with e.g. "a", any following blacklisted characters don't trigger the rule

Example:

q=abc -> rule does not match -> fine
q=Abc -> rule matches -> fine
q=abC -> rule does not match -> not fine

So when the forbidden characters are not the first character after "q=", the rule is not working.

What am I missing? Can someone help me?

BR

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

With your shown attempts, please try following htaccess rules file. 2 important points here, 1st you can use ^ in spite of .* in last forbidding Rule. 2nd is you need to use NC to cover lower case to match small and capital letters in regex.

RewriteCond %{REQUEST_URI} ^/generic/  [NC]
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]
RewriteCond %{QUERY_STRING} q=[^a-z]+ [NC]
RewriteRule ^ - [F]

OR use following rules to match exact query string use ^ and $ anchors to match exact query string value:

RewriteCond %{REQUEST_URI} ^/generic/  [NC]
RewriteCond %{REQUEST_METHOD} ^GET$ [NC]
RewriteCond %{QUERY_STRING}  ^q=[^a-z]+$ [NC]
RewriteRule ^ - [F]
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