Jump to content

ErrorDocument not working


pritam79

Recommended Posts

Hi all,I am trying this example forthe ErrorDocument directive. Firstly, i have made the following changes to my “httpd.conf” file.I have changed this code of the httpd.conf file

## Customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## Some examples:#ErrorDocument 500 “The server made a boo boo.”#ErrorDocument 404 /missing.html#ErrorDocument 404 “/cgi-bin/missing_handler.pl”#ErrorDocument 402 http://www.example.com/subscription_info.html#

To this

## Customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## Some examples:ErrorDocument 400 /error.php?400ErrorDocument 401 /error.php?401ErrorDocument 403 /error.php?403ErrorDocument 404 /error.php?404ErrorDocument 500 /error.php?500

After this, i have created a file “error.php”-

<html> <head> <title>Beginning PHP6, Apache, MySQL Web Development Custom Error Page </title> </head> <body><?phpswitch ($_SERVER['QUERY_STRING']) {  case 400:	echo '<h1> Bad Request </h1>';	echo '<h2> Error Code 400 </h2>';	echo '<p>The browser has made a Bad Request.</p>';	break;	   case 401:	echo '<h1> Authorization Required </h1>';	echo '<h2> Error Code 401 </h2>';	echo '<p>You have supplied the wrong information to access a secure resource.</p>';	break;   case 403:	echo '<h1> Access Forbidden </h1>';	echo '<h2> Error Code 403 </h2>';	echo '<p>You have been denied access to this resource.</p>';	break;     case 404:	echo '<h1> Page Not Found </h1>';	echo '<h2> Error Code 404 </h2>';	echo '<p>The page you are looking for cannot be found.</p>';	break;				     case 500:	echo '<h1> Internal Server Error </h1>';	echo '<h2> Error Code 500 </h2>';	echo '<p>The server has encountered an internal error.</p>';	break;	   default:	echo '<h1> Error Page </h1>';	echo '<p>This is a custom error page...</p>';}				   echo '<p><a href="mailto:sysadmin@example.com">Contact</a>  the system administrator if you feel this to be in error.</p>';?></body></html>

But when i open my browser and type http://localhost/nonexistent/page.html, (or any other page that doesn’t reside on my server), into the address bar I don’t get the Page Not Found message on the screen like the one below-

Page Not FoundError Code 404The page you are looking for cannot be foundContact the system administrator if you feel this to be in error

Instead i get this message-

Error PageThis is a custom error page...Contact the system administrator if you feel this to be in error.

Why is this not working? plz help...

Link to comment
Share on other sites

Most likely, the slash that's preceding the address is making it point somewhere you don't intend it to.Instead of /error.php?400 try error.php?400 and put error.php in the same folder as .htaccess.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...