How To Flush Rewrite Rules For All Sites on Multisite Network

Hello,

After updating plugins on multisite networks it is not uncommon for rewrite rules to be broken on many sites on the network.

Fixing the issue requires visiting each site and flushing the rules.

I am looking for a solution that will flush all the rules on all sites across the network.

These threads are relevant, but I am seeking a recommendation, code snippet or plugin to accomplish this task.

https://wordpress.org/support/topic/force-rewrite-rules-when-updating-in-multisite

http://shibashake.com/wordpress-theme/how-to-flush-permalink-rules-with-flush_rules

http://wordpress.stackexchange.com/questions/130423/add-rewrite-rule-not-working-in-wordpress-multisite

Any help appreciated.

Thanks,
Phil D

  • calvinrogercanas
    • New Recruit

    Hello @SooBahkDo,

    Thanks for your questions.

    It seems that the code posted here show some positive result based on the replies posted there. You can try it by inserting it to the functions.php of the activated theme in your multisite.

    Since this is out of my depth. I will also flag the Second-Line Support ( coding experts ) to give their valuable input. They may response slower than normal because they fix advance issues.

    Best Regards,
    Calvin

  • Hoang Ngo
    • Code Slayer

    Hi @SooBahkDo,

    I hope you are well today.

    Please try the small plugin I attached here, this will display a menu in your admin network. When you click on the button, it will loop through all blogs and force to flush the rules.

    If you have any issues please don't hesitate to let us know so we can assist.

    Best regards,
    Hoang

  • Hoang Ngo
    • Code Slayer

    Hi @SooBahkDo,

    I hope you are well today.

    Please note that, this will need to do manually. Flush rewrite rules needed to touch the database, so it's a little bit expensive if we let it run automatically.

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

  • SooBahkDo
    • Syntax Hero

    Hello,

    I see this plugin is only accessible to activate networkwide.

    After activation a menu item FLUSH ALL RULES appears in the network dashboard left hand menu.

    Clicking the menu item opens an admin page with a single button on it: CLEAR ALL

    When I click the button there is no visual indicator that the action is being taken. Is that as expected? It would be nice it if it displayed a progress indicator of some kind, so the user knows it completed the requested actions.

    After clicking the CLEAR ALL button, I checked several subsites that I knew had broken rules and their rules remained broken.

    Additionally, when I flushed the broken rules on those sites and clicked the CLEAR ALL button again, it REBROKE the rules again.

    Rather than fixing broken rules it appears to create more of them.

    Can you assist further?

  • Hoang Ngo
    • Code Slayer

    Hi @SooBahkDo,

    I hope you are well today and I'm sorry for the issue.

    The Flush All Rules actually have same effect when you click on the Save Button in Permanlink Option page.

    For now, Could you please follow this guide to enable the staff access?

    Also, please send me some example of broken sites too, that's will help me much for rewrite the script for fixing this problem.

    I'm sorry again for this inconvenience, and thanks a ton for your patience :slight_smile:

    Best regards,
    Hoang

  • SooBahkDo
    • Syntax Hero

    Hello Hoang,

    I will install this plugin on a test network with only a few subsites on it and try it there and then advise.

    It took me quite a while to flush 60 sites after trying it on a larger network, so I prefer to let you test on a non production network since the plugin seems to break rules on all sites.

    I'll grant access to that network as you requested shortly.

    Thanks

  • SooBahkDo
    • Syntax Hero

    Hello Hoang,

    All three sites on the network currently have broken rules.

    You can easily view (and flush) the broken rules on each site by using the Tools Menu >> Rewrite Rules.

    If you flush the rules during your testing and need for them to be broken again, so you can test again, you may be able to recreate the broken rules by upgrading a few plugins.

    Typically when plugins are upgraded some rules will break on some sites and then flushing each site is necessary to restore site functionality.

    I notice in the network dashboard that several plugins have upgrades available and you can upgrade some of them and then check individual sites to see if any rules are broken. Not all plugin upgrades cause broken rules, but is a frequent problem.

    However DO NOT upgrade WPMUDEV Ultimate Branding. The upgrade to 1.8.0.4 results in admin white screen and many debug errors. I wish this could be resolved so we could upgrade. The Ultimate Branding upgrade causes the same issue on multiple networks configured similarly. See this thread:

    https://premium.wpmudev.org/forums/topic/ultimate-branding-v1804-debug-errors#post-859196

    I removed the plugin Advanced Access Manager via FTP.

    I also removed the Flush all Rules plugin via FTP as it seemed to be running and rebreaking the rules even when I did not have it activated. Each time I flushed the rules and then checked them a while later, they were broken again even though I had not upgraded any plugins.

    Perhaps you can also determine what is causing this issue on the test site:

    https://premium.wpmudev.org/forums/topic/can-only-activate-one-plugin-at-a-time-in-network-dashboard?replies=1#post-859590

    If you require FTP credentials, please advise.

    The Flush All Rules plugin will be a valuable addition to a network admins tool set when you get it working properly.

    Thanks for your help.

  • Hoang Ngo
    • Code Slayer

    Hi @SooBahkDo,

    I has modified the plugin, in previous version, we trying to init the rewrite rules for each blog & flush them in network mode, however, at this stage, only native WordPress rules has been flushed, not the custom rules like the rules created by Custom Post Type.

    So the new way, I will send a signal to each blog to told it should re-flush the rules itself in init runtime, this can handle the flow better, can you please try it?

    Best regards,
    Hoang

  • SooBahkDo
    • Syntax Hero

    Hello,

    It appears to have flushed all but one rule on 3 sites and left many unflushed rules on the 4th site

    This was the only rule was NOT flushed on three sites
    ^cac-api-nossl/?$ index.php missing

    The rules that were NOT flushed on the 4th site are attached in a text file.

    I decided to try running the plugin a 2nd time to see if it cleared the remaining rules.

    After running the plugin a 2nd time, the same rules remained unflushed on each site.

    Thanks,
    Phil D

  • Hoang Ngo
    • Code Slayer

    Hi Phill,

    I hope you are well today and I'm sorry for the delay.

    If the rule not flush, perhaps that rule is added after the flush action. Can you please let me know which plugin using that rule? (^cac-api-nossl/?$ index.php missing)

    I'm sorry for this inconvenience and many thanks for your patience.

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.