SSO Rewrite Rules tend to be forgotten

Hi there!

I’ve been encountering this same issue for over a year now:

> Sometimes, either the mapped or main domain returns a 404 error when trying to access Single Sign On rules.

Is this a known issue?

And what are the exact rules? I might be able to apply them within .htaccess.


  • Adam Czajczyk
    • Support Gorilla

    Hello Sybre,

    I hope you’re well today and thank you for your question!

    I can see that you are using our Domain Mapping plugin but I admit I’m a bit confused. By SSO (Single Sign On) we usually refer in this case to the “Cross-domain autologin” option which is a simple “Yes/No” switch.

    As you are referring to the “rules” in the context of our Domain Mapping plugin I must say that I’m not sure what do you mean. I suppose I’m missing something obvious here so could you please elaborate a bit on this so I could better understand your question?

    Please advise!

    Best regards,


  • Sybre Waaijer
    • The Incredible Code Injector

    Hi Adam Czajczyk,

    Thanks for getting back to me.

    That’s exactly what I meant :slight_smile:. I’m loading those scripts in an asynchronous manner as per the options provided.

    The issue I’m facing is that the URLs generated through WordPress rewrite are sometimes lost (perhaps through a cron job?).

    Whatever is the case, the following happens:

    1. I log in to the main site (

    2. I go to any mapped domain, (e.g.

    3.a. Either URL a) results in 404.

    3.b. Or URL b) results in 404.

    URL a) is shown in the front-end script. URL b) is loaded within URL a)’s content.

    URL a)
    URL b)|1472821179|hash1|hash2&refresh=0

    3.a. Is resolved temporarily by flushing the permalinks (saving those settings) on the mapped domain.

    3.b. Is resolved temporarily by flushing the permalinks on the main domain.

    This happens on any site on the multisite network. I have no plugins active that actively adjust or flush the rewrite rules.

    I hope this clears things up! :slight_smile:

  • Dimitris
    • Support Star

    Hey there Sybre Waaijer,

    hope you’re doing good today and don’t mind chiming in! :slight_smile:

    I tend to believe that this is indeed a .htaccess conflict as saving permalinks re-constructs any rewrite rules by writing to this critical file. More info can be found here

    Having said that, it would be perfect if you can reproduce these 404 issues and take a copy of the .htaccess file at this moment. Then, resave permalinks in order to resolve it and take a second copy of the .htaccess. You can then rename these files like htaccess-old.txt and htaccess-new.txt and attach them here in a reply (files should not be hidden and should have a .txt extension in order to get attached in our forums). This comparison may give us some good info on what may interfere there.

    As far as I can understand this replication may be tricky though, as you mentioned that this is happening sometimes. Are there any updates or new plugins/themes installed in your WP installation that you recall before you start dealing with issues? Please advise! :slight_smile:

    Kind regards,


  • Sybre Waaijer
    • The Incredible Code Injector

    Thank you so much for your time Dimitris !

    I can’t recall what plugin has caused this, as it’s quite a long time ago.

    It’s either core, or one of my own (ugh..).

    I also made a post earlier about the rule initialization, found here.

    It’s mainly about the same issue, but this one is more focused on the .htaccess file rather than the plugin itself. The adjustment suggested to be working for the time being, but I soon ran into the same issue again.

    Unfortunately, I can’t afford disabling the current rules (they’re mostly disabling file browsing and forcing HTTPS on some sites), as some production sites rely on those rules within the network.

    I do believe hard-coding the required rewrite rules is a great possibility for a solution.

    If I encounter this issue again (I hope soon :smiley:) then I’ll see if forcing some rules would fix the problem.

    I’ll snoop into the code when the time comes.

    I’ll report back with the rules and results.

    Until then, have a wonderful day! Cheers!

  • Sybre Waaijer
    • The Incredible Code Injector

    Well, editing htaccess was impossible, as the variables that are checked against are pulled directly from WP_Rewrite’s caches.

    Nevertheless, I found the solution, and I already have it running on my website.

    I “simply” edited the ways the Rewrite endpoint is called on. I also added a key revision so the whole network got flushed correctly.

    Feel free to push the following file to the plugin author, let me know what you think!

    Patch file


    – The query vars are now correctly filtered into the right filter. Action init is not the right filter.

    – The flush now happens on shutdown, this will prevent plugin conflicts. As some plugins might add rewrite rules later than “init action 10”.

    – I cleaned up some code as I went through.

    – Flush revision key has been added.


  • Milan
    • WordPress Wizard

    Hello Sybre Waaijer ,

    Hope you are doing well today !!

    Thanks a lot for your patch. I’ll make sure that it gets our developer’s attention. I am glad that you made your fix on your own. Really great work.

    Furthermore, I can see that you are using an older version of Domain Mapping plugin. So would you please take some time and upgrade it to its latest release ? If you are not sure how it will go for your live site, then you can always create staging site to test update there. :slight_smile:

    Let me know if you have anything else to ask. :slight_smile:

    Best Regards,


  • Sybre Waaijer
    • The Incredible Code Injector

    Hello Milan,

    I just compared the two versions (, which I have installed, and the current at version

    No executable code differences are within the Cdsso.php file (for which the patch file is based upon).

    Throughout I only found textual improvements, and of course the “www.” fix.

    In no way are any changed in related to my changes so the patch file is still valid (but the lines might be a little off, at most by 3) :slight_smile:.

    If, for any technical reasons, you’d still wish to obtain an updated version compatible with the code lines in Feel free to ask and I’ll provide!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.