Apache RewriteCond with dynamic query string

Posted on 2008-11-06
Last Modified: 2008-11-06
I have the following rewrite in Apache2.2:
RewriteCond %{QUERY_STRING} =Action=Load&Merchant_Id=1&Section_Id=123
RewriteRule ^/sectionpage.php$ /sale [R=301,NC,L]

The Rewrite works correctly if the query string is an exact match. So
 rewrites to

But I need to also rewrite for all URLs that contain the query string anywhere

This should be a pretty basic rewrite but I am not getting it to work.
Question by:KirkSamuels
    1 Comment
    LVL 27

    Accepted Solution

    But the order of the variables is the same?

    Remove the '=' operator, which means that the string is a regular expression, which would match anything left or right to the string:

    RewriteCond %{QUERY_STRING} Action=Load&Merchant_Id=1&Section_Id=123
    RewriteRule ^/sectionpage.php$ /sale [R=301,NC,L]

    Open in new window


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now