Best method for a 301 redirect of a large amount of URL’s

[ad_1]

I’m helping a friend doing a long needed update on their WordPress site. The old site got roughly 5000 pages, all with the slug as URL, without any “folders”. So something like [domain.com/page-number-ome]), [domain.com/another-page]) and so on. On the new site, these pages should all be grouped based on the CPT they belong to, so it would be something like:

* [domain.com/cpt1/page-number-one])
* [domain.com/cpt3/another-page])

There isn’t anything in todays URL that makes it possible to identify what custom post type, a given URL belong to, so a general rewrite rule with some reg.ex might be impossible.

I was thinking of creating a script that generate a rewrite rule for each page, but that will result in a .htaccess file with more than 5000 lines, and that might not be the best solution, performance wise.

Another option might be to hook into parse\_request, and dynamically generate a rewrite/redirect, but that means another database call for each page view.

What would be the best way to solve this? I prefer to code something, and not use a plugin.

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer