PDA

View Full Version : Custom 404 Page


Randy
02-10-2004, 03:09 PM
Here's how to create a custom 404 page.

First, create the page you want to display. Save it as 404.php.

In that page, you can have certain things displayed. Just put the appropriate code where you want it displayed in your page. You can use this information on any other PHP page too.

Information available:


A query string, if you use dynamic pages

<?php echo $_SERVER["QUERY_STRING"]; ?>

The page the user came from

<?php echo $_SERVER["HTTP_REFERER"]; ?>

The page the user was trying to visit

<?php echo $_SERVER["REQUEST_URI"]; ?>

The user's IP address

<?php echo $_SERVER["REMOTE_ADDR"]; ?>

The user's browser

<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>



The next thing to do is to create an .htaccess file. These are special files that tell the web server how to behave. If you already have a .htaccess file, just add the information to the bottom.

Steps to create a .htaccess file from scratch:

[list]
Open your favorite text editor (TextEdit in plain-text mode on Mac OS X or Notepad on Windows).
Add this to the file:

ErrorDocument 404 /404.php

Save the document as ".htaccess". If you're on Mac OS X, don't type the quotes and don't append a file extension. If you're on Windows, include the quotes around the name.
Upload the .htaccess file to your www or public_html folder. See this post for FTP Instructions (http://forums.insiderhosting.com/showthread.php?s=&threadid=1606).

You're all set!

VxJasonxV
02-10-2004, 04:42 PM
Don't all Custom Error Pages have to be at least 5 (or is it 10?) KB in order for IE to use them?

mort
02-10-2004, 05:37 PM
Their was a comment in one of the updates that error pages nolonger need to be 10K.

And having tried randy's code (Uploading both .htaccess and 404.php to the public_html folder)

It does work.

The 404.php file I test with was only 656 bytes.

VxJasonxV
02-10-2004, 06:17 PM
They finally did away with the x-pad syndrome :P. Took long enough.

(x-pad syndrome: Making files bigger by padding tons of x's into the end of the file.)