How do I show the 404 page in the correct language in Episerver?

  • Page Owner: Not Set
  • Last Reviewed: 2020-01-24

The web.config allows me to redirect to a single path, but my site is multilingual and I want the 404 content to display in the correct language. How do I do this?


Answer

You'll need to create a Page not Found page type and create a page in Episerver with that type that has a consistent path across all languages (for example, /404).

Within the controller for that page type, you need to detect if you're in edit mode (if so, show normal content). If not, you'll need to detect what language from the referring URL and load that content.

For example, from BI: https://gitlab.blendinteractive.com/biw/bi-worldwide/blob/master/Web/Controllers/Pages/NotFoundPageController.cs

Next you will need to redirect 404 traffic to your page. In your web.config:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404" subStatusCode="-1" />
  <error statusCode="404" path="/404/" responseMode="ExecuteURL" />
</httpErrors>

Then test.

NOTE: If you have the SEO Toolbox (formerly Mogul SEO) plugin installed, and your 404 path does not end in a trailing slash, this can cause an infinite redirect loop. See: https://gitlab.blendinteractive.com/biw/bi-worldwide/commit/657827c318bd9ad9df266330a6268243db562ffe