I work with wordpress daily and haven't seen this issue before. Perhaps the SO community has some insight.
I have a standard wordpress install v4.3, which is the current version. I have no rewrite modules active. No base category or tags set. Permalinks are set to "Post name" for clean URLs, which works well for the whole site except everything under /blog
I have tried to rewrite /blog/* to index.php?page_id=xxx and wrote a custom parser to handle the URI segments, which seems to work locally. On the server, however, all /blog/xxx just redirects to /blog/ even though at no point do I specifically tell it to do this.
I have tried setting this in .htaccess:
RewriteRule blog/(category|tag|page|search)/(.+)/?$ index.php?page_id=123
which didn't work even though the regex checks out and every other rewrite rule I have for custom post types works.
When that failed I tried writing a rewrite rule hook:
// pathetic hack to fix wp permalink horror for blogs
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_action( 'wp_loaded','my_flush_rules' );
// flush_rules() if our rules are not yet included
function my_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if(isset($_GET['rules']))
{
echo '<pre>';
print_r($rules);
echo '</pre>';
}
if ( ! isset( $rules['blog/(category|tag|page|search)/(.+)/?$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
$newrules = array();
$newrules['blog/(category|tag|page|search)/(.+)/?$'] = 'index.php?page_id=123';
return $newrules + $rules;
}
Which, if you run ?rules in the browser displays the current rewrite array and it indeed is adding it to the array. Yet for some reason the action WP is taking is to redirect to index.php?page_id=123 instead of loading it and letting me parse out the URI myself. Like the word "blog" is somehow reserved.
Has anyone else seen anything like this? The only relevant plugin I can imagine might be disrupting things would be CCTM but the blogs are not custom content types. /blog is just a normal page like any other that fetches posts according to the URI segments.
I suggested trying to use the standard WP architecture for these pages but the client insists everything is under /blog/category/category_name/page/x for example. They don't want to budge on that and I understand because locally it works as expected. Yeah there are minor differences in the server settings but the common core elements are the same - htaccess is enabled, wp is the root and not installed in a directory, etc.
I've tried disabling all plugins, switching to 2015 theme, flushing permalinks, clearing cache, etc. Very strange.
Any input or similar stories may lead to the solution so I welcome what you have.