Forum Moderators: phranque

Message Too Old, No Replies

want a custom error page with a 404 status

         

arbitrary

12:53 am on Oct 16, 2005 (gmt 0)

10+ Year Member



I would like to know if it is possible to serve up a custom error page but still send back a status of 404.

For example. If you request:

www.example.com/abc but abc does not exist on my server, I would like to serve up:
www.example.com/missing.html which has a custom file not found message but I also want to send back a 404 status.

I tried to accomplish this with the following in .htaccess:

ErrorDocument 404 http://www.example.com/missing.html

This accomplishes serving up the error page but sends back a 302 found status.

Any thoughts on how to accomplish this would be appreciated. If this is something that can't be done, please let me know as well.

Thanks.

bsterz

2:19 am on Oct 16, 2005 (gmt 0)

10+ Year Member



Hmm..that's actually the correct way to do it - I don't know why it's setting the wrong header - are you sure you're looking at the header correctly? Try it with Ethereal - it's a good look at the response.

jdMorgan

2:20 am on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The correct syntax for 404 status is:

ErrorDocument 404 /missing.html

Use a local URL-path, not a canonical URL. See the ErrorDocument documentation [httpd.apache.org] for details.

Jim

arbitrary

5:51 am on Oct 16, 2005 (gmt 0)

10+ Year Member



bsterz, I tried to find a header checker at Ethereal but could not. I am using the following header checker which should be okay:

[searchengineworld.com...]

Jim, I tried using a local path and used the exact line you suggested:
ErrorDocument 404 /missing.html

When I tried that, it just give me the standard 404 through my browser and it could not find missing.html

I am not sure what it up. Because the local path is not working, does it point to something else perhaps being configured incorrectly.

arbitrary

6:11 am on Oct 16, 2005 (gmt 0)

10+ Year Member



Okay, all is working now as I am able to serve up the custom error page and still return a 404 response.

Jim, you were right - I needed a local path. It did not work the first time because my error message, missing.html was less than 512 bytes. (I was just testing with a short error message.) With the link you gave to the apache error documentation, I found out that IE will ignore error messages shorter than 512bytes and use its own error message. That is why it did not appear to work the first time.

When I used the local path and made the error message longer, it served up the custom error page and the 404 response.

Thanks Jim, bsterz for your help. I love this place!