Custom System Messages
This extension lets you define any 2 templates within your template groups to be used as the error page. You have access to all the usual variables from the Specialty Templates, plus a new one, referrer. So on top of any EE template tag you want to use in the error page, you have title, meta_refresh, heading, content, link, and referrer. link can also be changed to render without the JavaScript history.go() method if you desire. There are 3 options which I called Accessibility in the extension settings.
There is a known conflict with the Flash Messenger extension, which also extends the core Output class, and overrides Custom System Messages. To fix this, you can change Flash Messenger to extend this extension, instead of the core. In Flash Messenger change MyOutput extends Output to MyOutput extends System_Messages_Output.