Chaining/Combining query strings in .htaccess. Is this possible?

Is it possible to chain or combine query strings when writing RewriteCond or RewriteRules?

At the moment I have this in my .htaccess file…

RewriteCond %{QUERY_STRING} tiger [OR]
RewriteCond %{REQUEST_URI} tiger
RewriteRule ^ http://www.example.com/news/? [L,R=301]

RewriteCond %{QUERY_STRING} lion [OR]
RewriteCond %{REQUEST_URI} lion
RewriteRule ^ http://www.example.com/news/? [L,R=301]

RewriteCond %{QUERY_STRING} cheetah [OR]
RewriteCond %{REQUEST_URI} cheetah
RewriteRule ^ http://www.example.com/news/? [L,R=301]

All three matches are going to the same destination. Is it possible to do something like this or do I need to keep them all as separate lines?

RewriteCond %{QUERY_STRING} (tiger, lion, cheetah) [OR]
RewriteCond %{REQUEST_URI} (tiger, lion, cheetah)
RewriteRule ^ http://www.example.com/news/? [L,R=301]


Source: .htaccess

1 Comment

  1. Digin Dominic

    You can use regex alternation:

    RewriteCond %{QUERY_STRING} (tiger|lion|cheetah) [NC,OR]
    RewriteCond %{REQUEST_URI} (tiger|lion|cheetah) [NC]
    RewriteRule ^ http://www.example.com/news/? [L,R=301]

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.