My team is running into a very confusing error where our 404 pages are throwing 500 errors, but only when the Languages.AlwaysStripLanguage configuration setting is set to "false". When we remove the following, the 404's work; navigating to ACME.com/qwerty delivers content from ACME.com/404.
<settings> <setting name="Languages.AlwaysStripLanguage" value="false" /> </settings>
Oddly enough, when we add it back in, they still continue working for a time... and then eventually begin throwing 500's again. A bit of digging also revealed that what seems to be happening is that when you navigate to ACME.com/qwerty the website properly pursues a 404, but then gets caught in an infinite loop trying to load ACME.com/en/404. At least, according to the Failed Request Tracing.
Unfortunately, we need the Languages.AlwaysStripLanguage setting in place. Primarily because our website needs to work as such:
- (en-US Content) ACME.com
- (en-CA Content) ACME.ca
- (fr-CA Content) ACME.ca/fr
Our custom 404 logic came from the John Rappel article: https://www.geekhive.com/buzz/post/2017/07/a-complete-guide-to-configuring-friendly-error-pages-in-sitecore-part-1-404-pages/
Ultimately, the infinite loop seems to be happening because of this line from the Set404StatusCode class:
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.NotFound;
Where during this situation (and only this situation) this line throws an error stating that the status code can't be changed after it has been set.
Has anyone else run into problems running John Rappel's 404 code alongside setting Languages.AlwaysStripLanguage to false?
Am I missing something very obvious? Is there anything else I can provide to be more helpful?