Skip navigation
Currently Being Moderated

404 Error pages

Feb 1, 2013 1:34 PM

Right now I have my .htaccess setup so that if I go to www.website.com/nonexistantpage.htm it takes me to the proper 404 error page. But my website is built around php variables for the pages so to visit the home page it's not website.com/home.htm it's website.com/index.php?page=home

 

So if I do

 

website.com/index.php?page=nonexistant page

 

I jsut get a php error that the file does not exist. Instead of this happening I want it to also point to my error page. How do I set this up?

 
Replies
  • Currently Being Moderated
    Feb 1, 2013 3:45 PM   in reply to Gabriel McKenna

    This really depends on your site setup.  It really doesn't matter where the 404 error is or how it's accessed.  The point of the page is to make sure the user has somewhere to go.  So if it links to good pages that is all that matters.  However, if you start getting a lot of 404s you may want to setup 301 redirects to where users should end up.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 2, 2013 12:21 PM   in reply to Gabriel McKenna

    What do you have in the htaccess file because even with the variables apended to the end of the link it should still send the user to the custom error page.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 2, 2013 8:50 PM   in reply to Gabriel McKenna

    Type the following into the URL

    http://pb2.gabessdsp.hostzi.com/phpinfo.php

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 2, 2013 11:00 PM   in reply to Gabriel McKenna

    All you should need for redirecting to a 404 error page is the below:

     

    ErrorDocument 404 /error_page.php

     

     

    error_page.php being the custom page that the user will be redirected to if a page on the server has been deleted or moved.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 7, 2013 11:43 PM   in reply to Gabriel McKenna

    The way you have it now obviously doesn't work. I'd consult your host provider if you want to keep what you have now as it may be a server issue rather than anything do with which way you choose to implement a 404 error page.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 6:56 AM   in reply to osgood_

    If I recall correctly, you not supposed to specify the absolute path in the .htaccess file for error redirects because some servers won't like it.

     

    Maybe I'm wrong, but I've always done them as site root relative because of that nagging notion in the back of my mind...

     

    ErrorDocument 404 /index.php?page=error404

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 8:00 AM   in reply to Gabriel McKenna

    The url below SHOULD take you to the index.php IF the php is set up correctly.

     

    http://pb2.gabessdsp.hostzi.com/index.php?page=nonrealpage

     

    try include(content/nonrealpage.php) rather than require_once

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 8:23 AM   in reply to osgood_

    OK i see what you are saying now....humm.

     

    You just have one page and are using an include to bring in the content based on a link variable being passed.

     

    In the event of a page being listed in Google which no longer exists you want to be taken to an error page, right?

     

    Can you not write a bit of php code saying:

     

    <?php

    if ($page !== 'home' OR $page !== 'sewage' OR $page !== 'zoning') {

    header("Location: http://pb2.gabessdsp.hostzi.com/error.php");

    }

    else {

    $page = $_GET['$page'];

    }

    ?>

     

     

    OR maybe the otherway around

     

     

    <?php

    $page = $_GET['$page'];

     

    if ($page !== 'home' OR $page !== 'sewage' OR $page !== 'zoning') {

    header("Location: http://pb2.gabessdsp.hostzi.com/error.php");

    }

    ?>

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 8, 2013 10:05 AM   in reply to osgood_

    You could do it like below:

     

     

    <?php

    $page = $_GET['page'];

    ?>

    <?php

    if ($page == "nopage" OR $page == "notfound") {

    header ("Location: error.php");

    }

    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>Untitled Document</title>

    </head>

    <body>

    <a href="pass_variables.php?page=home">Home</a>

    <a href="pass_variables.php?page=sewage">Sewage</a>

    <a href="pass_variables.php?page=nopage">No Page</a>

    <p>

     

    <?php

    if($page == 'home') {

    include ('index.php');

    }

    elseif($page == 'sewage') {

    include ('sewage.php');

    }

     

    ?>

     

    </p>

    </body>

     

    </html>

     

    Only problem with that is you would have to append the missing page to the $page variable everytime. Small site easy but a bigger site not very economical

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points