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))

    //Rule 2
    $rewrite_rule2 = get_option('rewrite_rule2');  
    $rewrite_virtual_rule2 = get_option('rewrite_virtual_rule2');  
    if(!empty($rewrite_rule2) && !empty($rewrite_virtual_rule2))

    //Rule 3
    $rewrite_rule3 = get_option('rewrite_rule3');  
    $rewrite_virtual_rule3 = get_option('rewrite_virtual_rule3');  
    if(!empty($rewrite_rule3) && !empty($rewrite_virtual_rule3))

//    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

  • Could be anything. Did you check if the request is even routed through WordPress? If it does you could debug it further via wordpress.org/plugins/monkeyman-rewrite-analyzer Also you should note, that you shouldn't flush rewrite rules on init, but only on plugin activation. – s1lv3r Jan 20 '14 at 9:34
  • @s1lv3r - I've installed Monkeyman, but do not seem to pick up any rules I've defined any ideas?, although it works on my non multisite installation. Thanks on the hint about the flushing of rules/ – Roland Jan 20 '14 at 10:45
  • 1
    I'm having this same problem, and as far as I can tell it's related to bug #19896 on Trac. Basically, add_rewrite_rule doesn't work on Multisite/WordPress MU/Network installs. – Jay Mar 24 '14 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.