| Drupal
CustomError Module

We previously wrote a tutorial on how to create custom 403 and 404 pages in Drupal.

That tutorial used Drupal's built-in functionality, but that approach does have a few disadvantages.

So today we'll look at another approach, the CustomError module.

Pros and cons of different approaches

Drupal's built in functionality:

  • Pros: It's easy to use, quick, and doesn't require any modules.
  • Cons: It uses nodes for the pages. This presents potential problems with the pages showing up in search results and anything else that references nodes (e.g. a blog for popular content).

CustomError Module:

  • Pros: It doesn't use nodes and has additional features for customizing error pages.
  • Cons: It requires an additional module to maintain and it's a bit more set up.

Using the CustomError Module

CustomError Module for Drupal 403 and 404 Error Pages

At the bottom of the screen:

  • Enter "customerror/403" for the 403 option
  • Enter "customerror/404" for the 404 option
  • Save configuration
  • Go to Configuration > Custom Error.
  • Customize each of the error pages to your liking. Note, HTML can be used in the description.
  • Save configuration when done.

Finally, test your new 404 and 403 error pages.

As you can see, CustomError makes it simple to create custom error pages without using nodes.

Additional options

The CustomError module has two additional options:

  • Theme selection: allows you to select a different theme for the error pages. Note that both 403 and 404 errors will display using this one theme.
  • 404 Redirects: see below.

The 404 Redirect area allows you to specify 404 URLs that you'd like to redirect. To do so, enter the complete path of the page, add a space, then enter the absolute URL of the destination page.

For example, if I had a URL that was http://ostmdb.dd:old-login-page and I wanted to redirect it to http://ostmdb.dd:8083/user , then I'd use:

old-login-page http://ostmdb.dd:8083/user

You can add additional redirects on separate lines.

Pro tips for the CustomError module:

  • CustomError will attempt to match any URL that has the fragment you specified, not just complete URLs. For example, if you told it to look for "color", it will match /color/ , /colors/ , and /red-colors/ as 404 URLs that it should redirect.
  • The redirects will only work for 404 pages. If the URL generates a 404 response, only then will a redirect be looked for.
  • You can use regular expressions to match the 404 page(s).

About the author

Nick is the Director of Support at OSTraining and you can find him in almost every area of the site, from answering support requests and account questions to creating tutorials and software.