I have a Custom Post Type called 'Collections' with the following structure:
http://example.com/collections/artwork-name/
Now, this Collections CPT has 4 categories that I've added to the permalink as the following
http://example.com/collection/paintings/artwork-name/
http://example.com/collection/sculptures/artwork-name/
http://example.com/collection/drawings-watercolours/artwork-name/
http://example.com/collection/past-sales/artwork-name/
For SEO reasons I need to redirect the old URLs to the new one. The issue I'm facing is that since the URLs have now 4 different combinations I need to find a way to match the old URLs with the new ones by recognizing it's base category (each URL has just one category).
I have tried getting the current URL and see if contains the string portion /collection/ and which category it was part of but with no luck.
Another way I think it could work is to match the latest part of the URLs after /collections/ (old) and /collections/ (new) and then check which category it has.
I would do it by hand with htaccess but I have more than 500 URLs.
How would you solve this problem?