I have a fairly complex wordpress with multiple sub-directories:
example.com/sub1/
example.com/sub2/
I’m trying to implement some history/bookmark support, and to do that I need the URLS containing these directories to be rewritten to the directory, not the index page. From there AJAX can take over, interpret the first URL and load the content.
I believe to do this I need to use $wp_rewrite->non_wp_rules
So far I have not even been able to write a simple rewrite from one directory to another:
//flush the rules//
function test_flush_rewrites()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
};
//add new rule//
function test_add_rewrites()
{
global $wp_rewrite;
$test_new_non_wp_rules = array(
'sub1/' => 'sub2',
);
$wp_rewrite->non_wp_rules = $test_new_non_wp_rules + $wp_rewrite->non_wp_rules;
};
//add the actions//
add_action('generate_rewrite_rules', 'test_add_rewrites');
add_action('admin_init', 'test_flush_rewrites');
This results in a 404
when I navigate to the “sub1
” directory.
also
'sub1' => 'sub2' // does nothing
'/sub1/' => 'sub2' // does nothing
'/?sub1/' => 'sub2' // does nothing
I believe the rule i’d like to write in .htaccess
should look something like this:
RewriteRule ^([^/]+)/.*$ /$1/
ideally i’d like to redirect sub1/anythinghere
to sub1
, sub2/anythinghere
to sub2
and so on.
Thanks for any help.