I need to rewrite urls on a WordPress Network/Multisite, so I wrote a plugin that does it for me.
This plugin works perfectly when using on a Single WordPress site that does not make use of the Multisite feature, now when I try to use it on a Multisite setup it just does not want to work, nor writes to the htaccess file.
My code is below
function rewrite_builtrules() {
global $wp_rewrite;
//Rule 1
$rewrite_rule1 = get_option('rewrite_rule1');
$rewrite_virtual_rule1 = get_option('rewrite_virtual_rule1');
if(!empty($rewrite_rule1) && !empty($rewrite_virtual_rule1))
add_rewrite_rule($rewrite_virtual_rule1,$rewrite_rule1,'top');
//Rule 2
$rewrite_rule2 = get_option('rewrite_rule2');
$rewrite_virtual_rule2 = get_option('rewrite_virtual_rule2');
if(!empty($rewrite_rule2) && !empty($rewrite_virtual_rule2))
add_rewrite_rule($rewrite_virtual_rule2,$rewrite_rule2,'top');
//Rule 3
$rewrite_rule3 = get_option('rewrite_rule3');
$rewrite_virtual_rule3 = get_option('rewrite_virtual_rule3');
if(!empty($rewrite_rule3) && !empty($rewrite_virtual_rule3))
add_rewrite_rule($rewrite_virtual_rule3,$rewrite_rule3,'top');
// flush_rewrite_rules(true);
$wp_rewrite->flush_rules( true );
}
add_action( 'init', 'rewrite_builtrules' );
The urls that I need to rewrite are
www.site.co.za/multisite/wp-content/uploads/2014/01/images.jpg needs to become www.site.co.za/multisite/images.jpg
Is there anything I’m missing? Any help will be appreciated