Show 404 error if item or category does not exist

If a customer views an item or category that no longer exists, they'll receive an error message. To change this error to a 404 error page, you can mod the system as follows:

These instructions will point to your site's error page if the item or category can't be found. If you want to point to a different page, just change the URL in the location statement in all steps with the header location.

e.g.) To redirect to the home page, use:

@header ("location: $URL");

e.g.) To redirect to the /pages/aboutus.php page, use:

@header ("location: $URL/pages/aboutus.$pageext");

Do not point to a specific item or category page, as there could be a possibility of infinite redirection!

  1. Open the openinfo.php file in the /enc/ folder

  2. Version 2.82 or higher:

    Add the line:

    @header ("location: $URL/error.$pageext");
    die("Sorry, this page could not be found.");

    Just under the line:

    header("HTTP/1.0 404 Not Found");

    Version 2.7 through 2.81:

    Change the line:

    else
    $searchquery .= " AND ID='0'";

    to:

    else
    {
    $searchquery .= " AND ID='0'";
    header("HTTP/1.0 404 Not Found");
    @header ("location: $URL/error.$pageext");
    die("Sorry, this page could not be found.");
    }
  3. Find the line:

    if ($item)
  4. A little way under this code, change the code:

    if ($metanum == 1)
    {

    to:

    if ($metanum!=1)
    {
    @header("HTTP/1.0 404 Not Found");
    @header ("location: $URL/error.$pageext");
    die("Sorry, this page could not be found.");
    }
    else
    {
  5. Repeat step #4 for the $metanum line under:

    if ($catalog)
  6. Save and upload the changed files.