In what it does to rewrite rules, you have on the one hand what is external to wordpress (although wordpress also manipulates it) which is what you have defined in the .htaccess.
On the other hand you have Wordpress also internally manages rewrite rules.
When you create a CPT, rules are created automatically, for example, so you can access it by slug.
In addition to the rules that are created by default, you can add additional rules when you define the CPT. I do not know if you did that or not.
To solve the problem you have, it is necessary to watch the whole movie and it takes a lot of time, trial and error.
What I can give you are some tools:
1) For the .htaccess, you can activate the debug level of how the mod_rewrite is resolved. See as in this question This is displayed in the web server log.
2) For the rewrite rules of wordpress. Check the api from wp_rewrites as a starting point. In particular, the global variable wp_rewrite has all the rules that are in progress.
You'll probably have to hook a hook when parsea the query or when you finished parsear.
3) Something that is useful to me to debug in wordpress is to put a small homemade plugin that writes to the wordpress log ( ../wp-content/debug.log
) and from the code log the output doing write_log( print_r($variable,true));
Note: For production you must remove the home plugin and the write_log () that are in the code. And put all the definitions below in false.
wp-config:
...
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
...
plugin:
<?php
/*
Plugin Name: Logger
*/
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if (defined('WP_DEBUG_LOG') && true === WP_DEBUG_LOG){
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
}
EDIT I
These two functions with their hooks in the functions.php helped me with a project I worked on recently.
You can see how to solve the query and which rewrite rule is being applied internally in Wordpress.
/******* Para Debugging **********/
function print_rewrite_rules($a){
global $wp_rewrite;
write_log('wp_rewrite rules:');
write_log($wp_rewrite);
write_log('********');
write_log('Query Vars:');
write_log($a);
return $a;
}
add_filter('parse_request', 'print_rewrite_rules', 90, 1);
function print_parsed_request(&$args){
write_log('Parsed Request:');
write_log($args);
}
add_action('parse_request','print_parsed_request');