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

178
Visualizações
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 Respostas
Responde à pergunta

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 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