EDIT: As requested below, this is the entire ruleset for one product (obsolete now, as I should be able to consolidate these into ONE simple rule that looks for the productID#):
RewriteRule /mens-shirts-77/alice-in-wonderland-shirt-662.html$ http://www.domain.com/alice-in-wonderland-shirt-p160c3 [R=301] RewriteRule /womens-shirts-92/womens-alice-in-wonderland-shirt-872.html$ http://www.domain.com/alice-in-wonderland-shirt-p160c3 [R=301] RewriteRule /index.php?main_page=product_info*&products_id=(662|872)*$ http://www.domain.com/alice-in-wonderland-shirt-p160c3 [R=301]
And here's the original query string from above that I'm trying to wildcard down to just the productID:
I would like to consolidate the three line rulesets above into a single line (the productID is always attached to any form of the URL, it's the ONLY thing I need to reference from any incoming URL)... this is my first shot, which I believe now is not going to be that easy, but you get the idea:
RewriteRule *(662|872)*$ http://www.domain.com/alice-in-wonderland-shirt-p160c3 [R=301,L]
From what I understand now, I have to write out a regex that literally takes into consideration every single potential character in the URL's... but with that kind of overkill comes more potential for conflict... for example this rule works for the query string URL, but not the other two:
RewriteRule ^/[A-Za-z.?_=&]+[0-9]+[A-Za-z.?_=&]+(662|872)[A-Za-z.?_=&]+[A-Za-z0-9._%+-]+ http://www.domain.com/alice-in-wonderland-shirt-p160c3 [R=301,L]
So is it even possible to build a single regex that will handle BOTH forms of URL's (query string AND rewritten) in one formula?
I'm familiar enough with regex to make something, but I'm not familiar enough to understand the right and wrong way to do things... this is for a long history SEO migration to a new platform... I have to get this expression right, and ideally consolidated down to it's most minimal form (there's 300 URL's with multiple incoming versions that need to be accounted for, as shown above)... I don't think I should have 1000 htaccess rules on an already graphic heavy ecommerce site. :/
Thanks for taking a look... I really need to get this right the first time!