You have:
- A rewrite rule that handles the post being in the 5th part
- A rewrite rule to handle the taxonomy part
A rewrite rule to handle the post being in the 2nd or 3rd part isn’t in the above list, hence why you get a 404.
If we take this rewrite rule:
$newRules['basename/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?custom_post_type_name=$matches[4]'; // my custom structure will always have the post name as the 5th uri segment
And modify it slightly using some common sense, namely:
-
basename/(.+)/(.+)/(.+)/(.+)/?$ ….
custom_post_type_name=$matches[4]
// my custom structure will always have the post name as the 5 th uri segment
-
basename/(.+)/(.+)/(.+)/?$ ….
custom_post_type_name=$matches[3]
// my custom structure will always have the post name as the 4 th uri segment
-
basename/(.+)/(.+)/?$ ….
custom_post_type_name=$matches[2]
// my custom structure will always have the post name as the 3 th uri segment
etc
Place these in ascending order prior to your existing rule, and repeat as many times as is necessary