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!