|
-
Jan 15th, 2008, 01:56 PM
#1
[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.
-
Jan 15th, 2008, 02:00 PM
#2
Re: Am I throwing this 404 right?
Hmm, doesn't seem right. Just gives a blank page. I should try exit();
-
Jan 15th, 2008, 03:08 PM
#3
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...
-
Jan 15th, 2008, 03:58 PM
#4
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();
-
Jan 15th, 2008, 04:49 PM
#5
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.
-
Jan 15th, 2008, 05:01 PM
#6
Re: Am I throwing this 404 (or 301) right?
 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.
-
Jan 15th, 2008, 05:28 PM
#7
Re: Am I throwing this 404 (or 301) right?
Stop that. They may allow you to use it
-
Jan 15th, 2008, 11:03 PM
#8
Re: Am I throwing this 404 (or 301) right?
 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.
-
Jan 16th, 2008, 03:01 PM
#9
Re: Am I throwing this 404 (or 301) right?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|