homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Headers returned by ErrorDocument

 7:50 am on Mar 20, 2012 (gmt 0)

I am currently using ErrorDocument directive for my 404's in the below format:

ErrorDocument 404 http://www.domain.com/404.php

This does the task but the thing is when I did a header check on the website for any 404 pages they have a 302.

The thing is I don't know exactly what they should have in their header to qualify as the best practice for the website. Should they be returning a 302 or a 301 or should it be 404 itself!

If it should be a 404, I guess using a relative link with the ErrorDocument would suffice but for the 301, I do not know the code for it.



 7:55 am on Mar 20, 2012 (gmt 0)

try setting the header in 404.php

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

it should be a 404 to let search engines know that the link is broken.



 8:21 am on Mar 20, 2012 (gmt 0)

The 302 is returned because the ErrorDocument should point only to an internal path and filename not to a full URL with protocol and domain name.

The Apache manual page for the ErrorDocument directive specifically warns that including a domain name will generate an unwanted 302 response.

Adding the PHP code above will generate 404 instead of 200 when the 404 file is directly requested but won't help with the 302 problem when it is invoked as a server error message.

[edited by: g1smd at 8:23 am (utc) on Mar 20, 2012]


 8:21 am on Mar 20, 2012 (gmt 0)

Do not use protocol plus domain name in your ErrorDocument declaration, or it will turn into a redirect-- exactly what you're seeing.

Simply say

ErrorDocument 404 /404.php


 10:32 am on Mar 20, 2012 (gmt 0)

Thanks for the info, all of you, but still you didn't answer the real dilemma as to which should bee the header that those pages should ac..tually have.

Shouldn't a 404 be 301 redirected to a new 404.php page? Which is the best practice? (jamie has already given the answer in his last line but if someone could explain as to why shouldn't it be a 301 redirection, I'll be obliged - just for the information sake)

Any pointers would help...


 12:47 pm on Mar 20, 2012 (gmt 0)

you want the 404 status code for the requested url that was "Not Found".
if you instead provide a 301/302 status code - a 404 status code for the custom error document is too late to be useful.


 1:31 pm on Mar 20, 2012 (gmt 0)

thanks phranque,

Much appreciated.
I also got a resource on google's support forum -- [support.google.com...] that to a good extent helped understand the topic.

Thanks All

[edited by: engine at 1:58 pm (utc) on Mar 20, 2012]
[edit reason] fixed url formatting [/edit]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved