# Custom Error Pages

You can customize the error page that CommandBox servers return. You can have a setting for each status code including a default error page to be used if no other setting applies.

Create an `errorPages` object inside the `web` object in your `server.json` where each key is the status code integer or the word `default` and the value is a relative (to the web root) path to be loaded for that status code.

This is what you `server.json` might look like:

```
{
  "web" : {
    "errorPages" : {
      "404" : "/path/to/404.html",
      "500" : "/path/to/500.html",
      "default" : "/path/to/default.html"
    }
  }
}
```

You can set error pages via the `server set` command like this:

```
server set web.errorPages.404=/missing.htm
```

{% hint style="info" %}
For [Multi-Site](/embedded-server/multi-site-support.md), custom error page settings can be configured on a per-site basis in the `sites` object of the `server.json` or in a `.site.json` file.
{% endhint %}

## Accessing error variables

If your error page points to a CFM file, you can get access to the original path being accessed for 404s and the error that was thrown for 500s. To see all the request headers that are available, use the following snippet of code:

```javascript
req = getPageContext().getRequest();
names = req.getAttributeNames();
while( names.hasMoreElements() ) {
    name = names.nextElement();
    writeOutput( name & ' = ' & req.getAttribute( name ) & '<br>' );
}
```

An example of getting the original missing path in a 404 in Lucee would look like this:

```javascript
var originalPath = getPageContext().getRequest().getAttribute( "javax.servlet.error.request_uri" );
```

In Adobe ColdFusion, you can access `ServletRequest` Attributes directly via the CGI scope:

```javascript
var originalPath = cgi[ 'javax.servlet.error.request_uri' ];
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/custom-error-pages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
