XRouting, Contexts, secondary Context errors with 404

ModX 2.8.3-pl
PHP 7.3.12
XRouting - xrouting-1.4.1-pl

I have two directories.
apps. domain. com/site1/ - context: web
apps. domain. com/site2/ - context: site2

Each directory is for a different ‘looking’ site. The users know they are going to /site1/ or /site2/. There are different logins for both Contexts.

The application logic is stored in PHP and HTML files on the file system. I created ModX Chunks with the ‘Is Static’ checkbox checked and referencing the Static File on the file system.

There are duplicate ModX Resources in both Site1 and Site2 Context which point to the ModX Chunks with [[$ResourceApplicationContent]]

ModX and XRouting are at the top level for security to access the Resources.

For each directory, I have Resource Groups. Site1Admins, Site1Users, Site2Admins, Site2Users

When I first got everything setup, it worked perfectly with both contexts. Now that I am getting more users going to the /site2/ context, occasionally it quits working. It returns a 404 error when I try to access the apps. domain. com/site2/application.html

When I try to access apps. domain. com/site1/application.html, it continues to work.

This 404 error happened almost daily. To make it start working again, I would need to go to Manage → Clear Cache.

I thought maybe each Resource Group needed access to the /site2/ Context so I added that

Context: Site2 ‘Access Permissions’, I gave Site2Admins and Site2Users ‘User Groups’ - ‘Authority’ = 0, ‘Access Policy’ = Context

Adding the Resource Groups to the /site2/ Context keeps it working for a couple weeks, but then it starts to return a 404 error.

There is occasionally this error in the ModX log

[2022-04-07 08:15:12] (ERROR @ C:\directory\modx\core\model\modx\modresponse.class.php : 210) Attempted to redirect to an empty URL.

Does anyone know why ModX starts returning the 404 error and why clearing the cache fixes the error?

Thank you!

Make sure all user groups have at least load access (context access, not resource group access) to all of the contexts. Otherwise, if the cache gets cleared, XRouting may not be able to access the contexts to rebuild its cache files and route users accordingly.

1 Like

Thank you, markh!

I tried your suggestion in my test environment and both contexts kept working so I changed it in production. Hopefully this fixes it!

1 Like

Hello markh,

In my site2 Context, for each of my User Groups, I changed the Access Policy = Load Only. This worked until today and then site2/application.html started returning a 404 error.

Clearing the cache fixed the issue.

Do you have any other suggestions?

Thank you!

Hi @JamesInWA, do you have added the (anonymous) user group with authority 9999 and (at least) the Load Only permission?

Your issue still looks like, depending when the xrouting cache file is generated, a frontend user is not having permission to access the context. Resulting in the context details being missing in the xrouting cache file, than xrouting can’t resolve the context and returns the 404.

Hello christianseel,

Yes, I do have (anonymous) included in the Context Access Permissions with ‘Authority’ = 9999 and ‘Access Policy’ = Load Only.


The problem doesn’t affect one GB user. When this situation happens, all GB users will get a 404 error for all Resources (except the login Resource with no restrictions).

Thank you!

Hello christianseel,

Would you be willing to look at my setup and tell me what I am doing wrong? Either a Teams meeting or give you Admin access to ModX?

Thank you!

The same thing happened on Wednesday morning, I got a user email the GB Resources weren’t loading. I did the refresh cache and the Resources loaded.


On Saturday, I was converting another application over so the Resource code was on the file system. I noticed that file where the context cache is stored and it had updated.


When I opened up the PHP cached Context file, I saw that the GB Context was missing.


I opened the ModX Error log and saw

It looks like some of the installed Extras have been deprecated as well as the “Flat file processor support, used for action mgr/resources/getlist with path **** /modx/core/components/versionx/processors/mgr/resources/getlist.php, is deprecated since version 2.7.0.”

I did the refresh cache and the GB Resources loaded. On the Context Cache, I see both contexts.

Hopefully this might give more insite as to what is going on with my site? I would greatly appreciate any help or direction I should take.

Thank you!

Hello christianseel and markh,

What I have experienced is as soon as I save a Chunk or Snippet, the xrouting_contextmap.cache.php gets regenerated and it is missing the second context. I need to go to Manage → Clear Cache. This regenerates the xrouting_contextmap.cache.php with both contexts.

We decided to create another virtual server for the second company.

Thank you!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.