PDA

Click to See Complete Forum and Search --> : [RESOLVED] Am I throwing this 404 (or 301) right?


mendhak
Jan 15th, 2008, 12:56 PM
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)

mendhak
Jan 15th, 2008, 01:00 PM
Hmm, doesn't seem right. Just gives a blank page. I should try exit();

mendhak
Jan 15th, 2008, 02:08 PM
Addendum.

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



<?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...

mendhak
Jan 15th, 2008, 02:58 PM
404 solved, it was obvious. No output allowed after exit(), so I should 'get' the 404 page before I exit();


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

visualAd
Jan 15th, 2008, 03:49 PM
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.

mendhak
Jan 15th, 2008, 04:01 PM
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. :afrog:

visualAd
Jan 15th, 2008, 04:28 PM
Stop that. :mad: They may allow you to use it ;)

penagate
Jan 15th, 2008, 10:03 PM
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.

mendhak
Jan 16th, 2008, 02:01 PM
I'll do that, thanks.