Having a custom “page not found”, or 404 page, is an important modification for any website. It’s used to enhance the user experience by presenting an easy to understand message.
Setting up a user friendly error page is simple enough using Apache web server. Just modify the line in httpd.conf and point it to a static HTML document:
ErrorDocument 404 /the404_page.html
With JBOSS (or Tomcat-like Java container) application server, it’s slightly trickier. It has to be handled per web application basis. The change is done on the web.xml file, with these entries:
<web-app>
<error-page>
<error-code>404</error-code>
<location>/the404_page.html</location>
</error-page></web-app>
For the root directory, modify the web.xml in the ./deploy/jboss-web.deployer/ROOT.war/WEB-INF directory.
Testing this setup in Firefox and Opera, the custom 404 page will automatically show up properly.
However, with Internet Explorer, a “The Webpage Cannot Be Found” message comes up instead. This is a feature of IE to show Microsoft’s version of a “friendlier error message”. In this case, we want to disable it, so the custom 404 page will show up. It can be done via Internet Options -> Advanced tab :
Update: Microsoft Help & Support site states if the 404 error page is greater than 512 bytes, then IE will not show the friendly message. So the page size must be a bigger one, not just a simple one liner.
Now that the applications are setup to serve up custom error page, here are some examples of beautiful 404 page designs to improve the user experience.
I must agree with you! I use htaccess to control my 404 error pages, though it’s currently turned off for testing other things. I don’t like the fact that my htaccess command redirects users, changing the URL. I like to know what I typed or what the “wrong” link was to see if it was a minor mistake, such as “www.example.com/test,html” I’ve seen small mistakes like that a few times.
It leaves an especially bad taste when number one, I get a 404 error for a website just because I didn’t type in “www” and number two, when that 404 error page is worthless! lol
I wrote to a college I attended telling them they should change their root domain to be the same as www, because not everyone wants or does type in www. They looked like two completely different websites. Now they’re cool though 😉
Hi David,
You’re right. I get complaints from the business saying they automatically type in “www” in all URL addresses. So that pretty much became the standard URL for our company’s sites. Now I find myself having to set redirections to http://wwww.
This is a true noob question. Where in the structure would you actually put the /the404_page.html page?
Will, if you don’t use a web server proxy, then you can put the404_page.html file under $JBOSS_HOME/server/default/deploy/ROOT.war directory.