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]