Results 1 to 9 of 9

Thread: [RESOLVED] Am I throwing this 404 (or 301) right?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Resolved [RESOLVED] Am I throwing this 404 (or 301) right?

    PHP Code:
    header("HTTP/1.0 404 Not Found"); 

    Is that all there is to it, or should I be doing something else? Should I be sending a Location header as well? (I've defined a 404 page in my .htaccess)
    Last edited by mendhak; Jan 15th, 2008 at 03:07 PM.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Am I throwing this 404 right?

    Hmm, doesn't seem right. Just gives a blank page. I should try exit();

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Am I throwing this 404 (or 301) right?

    Addendum.

    I have an index.php which I want to 301 redirect to xyz.php. I try this:

    PHP Code:

    <?php

    header
    ("HTTP/1.1 301 Moved Permanently");
    header("Location: /xyz.php");
    exit();

    ?>
    But I get "Cannot modify header information", because index.php already exists...

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Am I throwing this 404 (or 301) right?

    404 solved, it was obvious. No output allowed after exit(), so I should 'get' the 404 page before I exit();

    PHP Code:
    header("HTTP/1.0 404 Not Found");
    include 
    realpath($_SERVER['DOCUMENT_ROOT'] . '/404.html'); 
    exit(); 

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Am I throwing this 404 (or 301) right?

    Is there a reason you cannot use the ErrorDocument directve in Asplache? It's better to do this if possible rather than include you own page.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Am I throwing this 404 (or 301) right?

    Quote Originally Posted by visualAd
    Is there a reason you cannot use the ErrorDocument directve in Asplache? It's better to do this if possible rather than include you own page.

    Because Asplache ate my toenails.

    Also, not all shared hosts give you this kind of access. I have .htaccess access. Maybe if I write to my host's admins, they'll give me Asplache access.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Am I throwing this 404 (or 301) right?

    Stop that. They may allow you to use it
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Am I throwing this 404 (or 301) right?

    Quote Originally Posted by mendhak
    PHP Code:
    header("HTTP/1.0 404 Not Found"); 

    Is that all there is to it, or should I be doing something else? Should I be sending a Location header as well? (I've defined a 404 page in my .htaccess)
    You cannot do both. If you have access to your .htaccess file you should be able to use the ErrorDocument directive and bypass PHP altogether. If you are rewriting all URLs to a PHP script then you should use the header() and include() method.

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Am I throwing this 404 (or 301) right?

    I'll do that, thanks.

Posting Permissions

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



Click Here to Expand Forum to Full Width