I am trying to match both a filename and querystring in my .htaccess file. When using an online testing tool (this one), it tells me that the conditions are being met, but the following rule doesn't run. What am I doing wrong?

Here's the mod_rewrite part of my .htaccess file:

RewriteCond %{REQUEST_URI} ^/omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba.php [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?cat=1(&.*)pr=4$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*&)?cat=1(&.*)pr=1$ [NC]
RewriteRule https://www.example.com/bagno-seta-mandorla/ [QSD,R=301,L]

And here's the URL it's supposed to redirect:

  • "it tells me that the conditions are being met" - but if you try those directives in that tool it states "This rule was not met."? "the URL it's supposed to redirect" - although the directives you've posted suggest the URL (query string) can be a little more varied - this should be clarified in the question.
    – MrWhite
    Aug 5, 2021 at 21:08
  • Just to add, that tool is perhaps a little misleading... on a real Apache instance, because the "rule was not met", the preceding conditions would never actually be processed.
    – MrWhite
    Aug 5, 2021 at 21:24

1 Answer 1


A pattern and argument is missing to your RewriteRule line.

You also probably can simplify this rule like the following:

# if the path is "/omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba.php"
# and the query string contains a cat parameter valued to "1"
RewriteCond %{QUERY_STRING} (?:^|&)cat=1(?:&|$)
# and the query string also contains a pr parameter valued to "1" or "4"
RewriteCond %{QUERY_STRING} (?:^|&)pr=[14](?:&|$)
# then redirect permanently to https://www.example.com/bagno-seta-mandorla/ (without keeping the old query string by the QSD option)
RewriteRule ^omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba\.php$ https://www.example.com/bagno-seta-mandorla/ [QSD,R=permanent,NC,L]

(supposing the .htaccess is in / directory)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.