Error Pages

Learn how to customize Error Pages for routes not found, maintenance mode, and internal redirect errors provided by the web server.

Customizing the error page

To customize it, you can edit the system/error.php file. This file is only triggered under the following conditions:

  • IIS performs an internal error redirection via <error statusCode="..." ... />.
  • Apache performs an internal error redirection via ErrorDocument.
  • nginx performs an internal error redirection via error_page.
  • No route matches the current HTTP request (404 status code).
  • An existing route is accessed, but the requested method is not defined (405 status code).
  • Maintenance mode is enabled (503 status code).

In the system/errors.php file, you can configure your View to customize an error page like this:

<?php use Inphinit\App; use Inphinit\Http\Request; use Inphinit\Http\Status; use Inphinit\Viewing\View; switch ($code) { case 403: // system/views/errors/403.php View::render('errors.403'); break; case 503: // system/views/errors/503.php View::render('errors.503'); break; default: // system/views/errors/generic.php View::render('errors.generic', ['code' => $code]); }

Possible status codes

In addition to 404 (in case of absence of a corresponding route) and 503 (maintenance mode), the other codes possible to receive in the variable $code are 403 and 500 due to the default settings in .htaccess, web.config or nginx.

Default .htaccess

# Redirect page errors to route system ErrorDocument 403 /index.php/RESERVED.INPHINIT-403.html ErrorDocument 500 /index.php/RESERVED.INPHINIT-500.html

Default web.config

<error statusCode="403" responseMode="ExecuteURL" path="/index.php/RESERVED.INPHINIT-403.html?INPHINIT_REDIRECT=1" /> <error statusCode="500" responseMode="ExecuteURL" path="/index.php/RESERVED.INPHINIT-500.html?INPHINIT_REDIRECT=1" />

You may add other status codes that are commonly encountered on your server.

Go to homepage
Star us on Github