htaccess rewrite, similar keyword items in strings

My web host is upgrading something so I have to redirect all my current Miva cart pages to new ShopSite URL's. I am trying to do that in my .htaccess file but the names of many of my products share similarities, as shown by the two examples below. What I have below always pulls up the first item in addition to pulling up the second item when I test the second redirect. How can I fix this?

RewriteCond %{QUERY_STRING} ^(.*)Product_Code=A363(.*)$ [NC]
RewriteRule .? https://shop.mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e&dbname=products&guid=da713abc-0c58-11e8-9836-002590155d56&function=add [QSD,L,R=301]

RewriteCond %{QUERY_STRING} ^(.*)Product_Code=A363DT(.*)$ [NC]
RewriteRule .? https://shop.mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90&dbname=products&guid=da713abc-0c58-11e8-9836-002590155d56&function=add [QSD,L,R=301]

Open in new window

pkromerAsked:
Who is Participating?
 
Dr. KlahnPrincipal Software EngineerCommented:
Put the most specific redirects first.  You can also trim down the regex length; the leading and trailing (.*) are not necessary.

RewriteCond %{QUERY_STRING} Product_Code=A363DT [NC]

Open in new window


This will operate only on item codes beginning with A363DT.  Since the RewriteRule includes the [L] action, this will be the last evaluation for this request.

If there is no match, the request will fall through and the succeeding conditionals will be evaluated.

RewriteCond %{QUERY_STRING} Product_Code=A363 [NC]

Open in new window


This will operate on any item code beginning with A363.
0
 
pkromerAuthor Commented:
Sorry for the delay, I'll try what you submitted tomorrow.
0
 
pkromerAuthor Commented:
so remove just the two (.*), or also remove the ^ and the $

?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Dr. KlahnPrincipal Software EngineerCommented:
Use the RewriteCond exactly as I showed it.  There is no need for the leading and trailing anchors, or the "gobble-ups".
0
 
pkromerAuthor Commented:
Ok, got rid of them, here's what I have:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=MBS4436DL [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da71789c-0c58-11e8-bb1d-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=NGA3636DL [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=9550c46a-18f2-11e8-9bf6-003048907ace&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=GA3636DL [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=c2fd871e-18f1-11e8-bb12-003048907ace&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=NGA3636 [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=6a0f8b6e-1830-11e8-8d36-003048907ace&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=GA3636 [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da713abc-0c58-11e8-9836-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418G [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da703c16-0c58-11e8-8e8e-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418C [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6fc524-0c58-11e8-848e-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418F [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da7077c6-0c58-11e8-9d5f-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418H [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6f12aa-0c58-11e8-ae59-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418M [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6f89c4-0c58-11e8-90c7-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418R [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da70005c-0c58-11e8-8ecc-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418T [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da70b31c-0c58-11e8-8f6d-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418V [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6f4e14-0c58-11e8-9027-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418W [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da70ee86-0c58-11e8-8ea5-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW418 [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6ed6dc-0c58-11e8-8b79-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417C [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6d710c-0c58-11e8-b68f-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417D [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6d3548-0c58-11e8-b70f-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417E [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6e5eaa-0c58-11e8-b3fe-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417F [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6c7d1a-0c58-11e8-80b3-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417N [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6cbe4c-0c58-11e8-a1a1-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW4170 [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6cf98e-0c58-11e8-a14c-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417R [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6e2340-0c58-11e8-9d9d-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417T [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6de79a-0c58-11e8-b973-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417W [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6e9ac8-0c58-11e8-8b77-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417Y [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6dac4e-0c58-11e8-b12b-002590155d56&function=add [QSD,L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} Product_Code=SW417 [NC]
RewriteRule .? https://mysite.com/cgi-bin/sc/order.cgi?storeid=*14c90e2aba9d40b616f51285&dbname=products&guid=da6c25d6-0c58-11e8-a40f-002590155d56&function=add [QSD,L,R=301]

Open in new window

I click on Product_Code=GA3636, that worked fine. Then I click on Product_Code=GA3636DL, it goes to Product_Code=GA3636. Then I tested the ones that have 418 in them, some work, some just go back to the one with just 418, not 418W or whatever.
0
 
Dr. KlahnPrincipal Software EngineerCommented:
I'm sorry, I'm having trouble reading this.  Remove all except the first instance of RewriteEngine On and RewriteBase, restart Apache, and then try again.
0
 
pkromerAuthor Commented:
That did it. Thanks very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.