SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)

    404 Error Page in PHP

    Is there any way to capture the information as to what page was not found when the not found page that is redirected to using the "ErrorDocument 404" statement in the .htaccess file can process PHP?

    $_SERVER["REQUEST_URI"] points to the "not found" page and I am trying to find out what page was requested that got redirected there.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,834
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Try this:
    PHP Code:

    <?php /* missing.php to be saved in your root directory */

    /*
        Apache config file: 'httpd.conf'
        requires activating:  ErrorDocument 404 /missing.php
    */

    echo 'This file: '__FILE__;
    echo 
    '<br />';

    echo 
    'Original file request: ',
           (isset(
    $_SERVER['REDIRECT_URL'])) 
           ?  
    $_SERVER['REDIRECT_URL'
           :  
    'NO REDIRECT_URL';

    echo 
    '<br />';

    echo 
    'Original file request: ',
           (isset(
    $_SERVER['REDIRECT_URI'])) 
           ?  
    $_SERVER['REDIRECT_URI'
           :  
    'NO REDIRECT_URI';

    echo 
    '<pre>';
        
    print_r($_SERVER);
    echo 
    '</pre>';


    .
    Last edited by John_Betong; Jun 11, 2010 at 21:36. Reason: Added REQUEST_URI
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Okay, I tried that and there's no redirect header and all the page references that do exist are to the not found page.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,834
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by felgall View Post
    Okay, I tried that and there's no redirect header and all the page references that do exist are to the not found page.
    It worked fine for me but I did have to de-activate my personalised .htaccess file.

    Did you:
    1. make the changes to your Apache http.conf file?
    2. after the changes stop and restart your LOCALHOST server?
    3. try the REQUEST_URI instead of REQUEST_URL server variable?
    4. check for an alernative server variable in the print_r($_SERVER) list?

    If all the above checks are OK then I think you will need a .htacces expert.



    .
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Thanks for the help.

    Finally figured out that all the info about what was being requested was being blocked because the ErrorDocument statement in the .htaccess file was fully qualified including the domain name. I have now changed it to just specify the notfound filename after a slash and $_SERVER["REQUEST_URI"] now contains the page that was requested that wasn't found.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •