1

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?

1 Answer 1

0

At the end of the day, you'll be putting stuff into your .htaccess file. But, could speed things up via the following method...

You want to end up with two lists, taken from the wp_posts table. Both lists have the same fields/columns: Post ID; and Post URL.

List 1 - created without the posts being put into categories

List 2 - created after you've put them all into categories.

Then, as both lists will have the same Post ID column, you can merge them together:

`Old URL      |      New URL`
 -------------|--------------
 post1 old url| post 1 new url

Then you can generate a list of stuff to paste into your .htaccess file. You could write a simple script to turn each row in the above list into:

Redirect 301 post1/old/url post1/new/url

There are an infinte number of ways to go about doing each of the above steps, but I'm sure you'll be able to figure one out. Will be basic PHP and MySQL queries. Maybe it will be possible to generate the first two list directly from phpmyadmin and export as CSV.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.