.htaccess redirect query string using mod_rewrite to another query string

I recently had the need to redirect one query string to another query string. The reason for this was we created a new item in our Zen Cart software that took the place of 3 other items. To make sure the search engines and our visitors reached the new product instead of the old ones, the following code was used to redirect them accordingly.

RewriteEngine on
RewriteCond %{query_string} products_id=(2928|2929|2930) [NC]
RewriteRule ^index.php$ /index.php?main_page=product_free_shipping_info&products_id=2995 [R=301,L]

As you will see, the 3 numbers in the regular expression represent the 3 old items being replaced on the RewriteCond line. The RewriteRule line takes the matching requests and redirects them to the new item using the appropriate products_id.

Hope this helps someone else looking for a similar solution.

Leave a Reply

Your email address will not be published. Required fields are marked *