Show a missing page error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    Show a missing page error

    Assume this case:
    • User requests for a page: my-page.php.
    • If the page is available, the browser shows the page.
    • But if the page is missing, the browser gets redirected to a page with address:
      missing_page.ph p?page=my-page.php


    How can this be done?
  • nashruddin
    New Member
    • Jun 2008
    • 25

    #2
    If you are using Apache, provide .htaccess file like this:

    Code:
    ErrorDocument 401 error.php?code=401
    ErrorDocument 403 error.php?code=403
    ErrorDocument 404 error.php?code=404
    The configuration above will display error.php for HTTP error 401, 403 and 404. And error.php might looks something like this:

    Code:
    <?php
    switch($_GET['code']) {
      case '401':
        print "Error 401 - Authentication Required!";
        break;
      case '403':
        print "Error 403 - Access Forbidden!";
        break;
      case '404':
        print "You have requested for page " . $_SERVER['REQUEST_URI'] . " which doesn't exist.";
        break;
    }
    ?>

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      So I think I need this as in .htaccess

      [code=Apache]ErrorDocument 404 missing_page.ph p?page=$_SERVER['REQUEST_URI'][/code]

      Comment

      • realin
        Contributor
        • Feb 2007
        • 254

        #4
        Originally posted by hsriat
        So I think I need this as in .htaccess

        [code=Apache]ErrorDocument 404 missing_page.ph p?page=$_SERVER['REQUEST_URI'][/code]
        $_SERVER['REQUEST_URI'] wont work in .htaccess i guess

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by realin
          $_SERVER['REQUEST_URI'] wont work in .htaccess i guess
          pretty good point!!!

          Then how to solve this?

          [EDIT: Solved: Instead of using $_GET['page'] in missing_page.ph p, I can utilize $_SERVER['REQUEST_URI']]

          Comment

          Working...