send default apache 404 error from php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • humbads@gmail.com

    #1

    send default apache 404 error from php

    How can I trigger the default Apache 404 error from PHP? I don't want
    to specify a custom handler, I want the default handler. The reason is
    that I am using mod_rewrite with Apache for my site. If certain a
    certain page is requested that is not published, then I want to send
    the apache default 404 error page. Currently, I am doing this to
    return a custom error.

    if($pageNotPubl ished) {
    header("HTTP/1.1 404 Not Found");
    // How do I send the default apache 404 message
    // instead of the message below?
    print("<html><b ody>HTTP 404 - Not Found</body></html>");
    exit();
    }

    The default 404 error page has more details, and I would rather not
    recreate it.

  • R. Rajesh Jeba Anbiah

    #2
    Re: send default apache 404 error from php

    humbads@gmail.c om wrote:
    <snip>[color=blue]
    > if($pageNotPubl ished) {
    > header("HTTP/1.1 404 Not Found");
    > // How do I send the default apache 404 message
    > // instead of the message below?
    > print("<html><b ody>HTTP 404 - Not Found</body></html>");[/color]

    Hmm..What about readfile() here?

    --
    <?php echo 'Just another PHP saint'; ?>
    Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

    Comment

    • humbads@gmail.com

      #3
      Re: send default apache 404 error from php

      > if($pageNotPubl ished) {[color=blue]
      > header("HTTP/1.1 404 Not Found");
      > // How do I send the default apache 404 message
      > // instead of the message below?
      > print("<html><b ody>HTTP 404 - Not Found</body></html>");[/color]
      [color=blue]
      > Hmm..What about readfile() here?[/color]

      Thanks for your reply. readfile won't work because the 404 message
      contains dynamic information like the requested URL. It looks like
      this:

      Not Found
      The requested URL /alkdf was not found on this server.
      Apache/1.3.33 Server at mywebsite.com Port 80

      Of course, I could recreate it using PHP functions, but for
      consistency, I'd rather have PHP pass through to Apache's default 404
      error handler. I think this is a tough question, any experts want to
      take it? In the meantime, I'll cross post my question in the Apache ng.

      Comment

      • Micha³ Wo¼niak

        #4
        Re: send default apache 404 error from php

        One quick glance of an experienced eye allowed to understand the blurred
        and almost unreadable humbads@gmail.c om's handwriting:
        [color=blue][color=green]
        >> if($pageNotPubl ished) {
        >> header("HTTP/1.1 404 Not Found");
        >> // How do I send the default apache 404 message
        >> // instead of the message below?
        >> print("<html><b ody>HTTP 404 - Not Found</body></html>");[/color]
        >[color=green]
        >> Hmm..What about readfile() here?[/color]
        >
        > Thanks for your reply. readfile won't work because the 404 message
        > contains dynamic information like the requested URL. It looks like
        > this:
        >
        > Not Found
        > The requested URL /alkdf was not found on this server.
        > Apache/1.3.33 Server at mywebsite.com Port 80
        >
        > Of course, I could recreate it using PHP functions, but for
        > consistency, I'd rather have PHP pass through to Apache's default 404
        > error handler. I think this is a tough question, any experts want to
        > take it? In the meantime, I'll cross post my question in the Apache
        > ng.[/color]

        What about $err404=readfil e('some/non-existant.file') ;
        str_replace('so me/non-existant.file', 'your_file', $err404);?
        :)

        Cheers
        Mike

        Comment

        • Micha³ Wo¼niak

          #5
          Re: send default apache 404 error from php

          One quick glance of an experienced eye allowed to understand the blurred
          and almost unreadable Micha³ Wo¼niak's handwriting:
          [color=blue]
          > One quick glance of an experienced eye allowed to understand the
          > blurred and almost unreadable humbads@gmail.c om's handwriting:
          >[color=green][color=darkred]
          >>> if($pageNotPubl ished) {
          >>> header("HTTP/1.1 404 Not Found");
          >>> // How do I send the default apache 404 message
          >>> // instead of the message below?
          >>> print("<html><b ody>HTTP 404 - Not Found</body></html>");[/color]
          >>[color=darkred]
          >>> Hmm..What about readfile() here?[/color]
          >>
          >> Thanks for your reply. readfile won't work because the 404 message
          >> contains dynamic information like the requested URL. It looks like
          >> this:
          >>
          >> Not Found
          >> The requested URL /alkdf was not found on this server.
          >> Apache/1.3.33 Server at mywebsite.com Port 80
          >>
          >> Of course, I could recreate it using PHP functions, but for
          >> consistency, I'd rather have PHP pass through to Apache's default 404
          >> error handler. I think this is a tough question, any experts want to
          >> take it? In the meantime, I'll cross post my question in the Apache
          >> ng.[/color]
          >
          > What about $err404=readfil e('some/non-existant.file') ;
          > str_replace('so me/non-existant.file', 'your_file', $err404);?
          > :)
          >
          > Cheers
          > Mike[/color]

          Ooops, sorry, readfile reads the file into the buffer... My mistake.

          Cheers
          Mike

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: send default apache 404 error from php

            humbads@gmail.c om wrote:[color=blue][color=green]
            > > if($pageNotPubl ished) {
            > > header("HTTP/1.1 404 Not Found");
            > > // How do I send the default apache 404 message
            > > // instead of the message below?
            > > print("<html><b ody>HTTP 404 - Not Found</body></html>");[/color]
            >[color=green]
            > > Hmm..What about readfile() here?[/color]
            >
            > Thanks for your reply. readfile won't work because the 404 message
            > contains dynamic information like the requested URL. It looks like
            > this:
            >
            > Not Found
            > The requested URL /alkdf was not found on this server.
            > Apache/1.3.33 Server at mywebsite.com Port 80
            >
            > Of course, I could recreate it using PHP functions, but for
            > consistency, I'd rather have PHP pass through to Apache's default 404
            > error handler. I think this is a tough question, any experts want to
            > take it?[/color]

            I think, Chung Leong can answer your question--he was hacking Apache
            for sometime ago.
            [color=blue]
            > In the meantime, I'll cross post my question in the Apache ng.[/color]

            Yes, that might help.

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            Working...