Dave's Brain

Browse - computer tips - good and easy apache 404 page

Date: 2011oct15
Product: Apache

Q.  How can I make a good/easy custom 404 (page not found) page?

A.  Add this directive to your httpd.conf file:

	ErrorDocument 404 /404.cgi

Or it can be done individually for virtual hosts.
Create the 404.cgi file that is mentioned:

	#!/usr/bin/perl
	print <<EOF
	Content-type: text/html
	Status: $ENV{REDIRECT_STATUS} Condition Intercepted

	<head>
	<title>404 Not Found</title>
	<link rel=stylesheet href=/css/mysheet.css type=text/css>
	</head>
	<h1>Page not found</h1>
	<p>
	Sorry page $ENV{REDIRECT_URL} doesn't exist any more.
	<p>
	There is other good stuff on the <a href=.>home page</a>
	EOF

Make 404.cgi executable.
Restart Apache.  Which is:

	/sbin/service httpd restart

On Fedora/RedHat.

What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: