How to Change the Site’s Default 404 Error Not Found Page

The apache’s default “404 Error not found” page seems ugly. And may some hosting service put theire ads in it. We can add some entry in .htaccess to change the defualt 404 error page. This method can also be used for some other error codes. A list of the server returned codes can be found in Table 1.

It simply need to add the “ErrorDocument” command to the .htaccess file. The format is:

ErrorDocument code /dir/file.ext


ErrorDocument code

For example:

ErrorDocument 404 /404.html

would cause any error code resulting in 404 to be forwarded to

ErrorDocument 404

would cause any error code resulting in 404 to be forwarded to

For other error code such as 401 the method is the same. But not all the returned code should be forwarded. Most of the time, forwarding the error codes is enough.

Table1: Server returned codes

Successful Client Requests
203Non-Authorative Information
204No Content
205Reset Content
206Partial Content
Client Request Redirected
300Multiple Choices
301Moved Permanently
302Moved Temporarily
303See Other
304Not Modified
305Use Proxy
Client Request Errors
400Bad Request
401Authorization Required
402Payment Required (not used yet)
404Not Found
405Method Not Allowed
406Not Acceptable (encoding)
407Proxy Authentication Required
408Request Timed Out
409Conflicting Request
411Content Length Required
412Precondition Failed
413Request Entity Too Long
414Request URI Too Long
415Unsupported Media Type
Server Errors
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout
505HTTP Version Not Supported

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *