I am trying to set-up a custom 404 page that logs the error details, referrer etc.

In my htaccess file if I use an exact url, i.e.
ErrorDocument 404 http://www.mysite.com/404.php

It finds the page ok when there is an error.

If I use a relative url, i.e.:
ErrorDocument 404 /404.php
or
ErrorDocument 404 404.php

It doesn't like it. Any ideas?

I need to use a relative url as when I use an exact url it doesn't store the page requested by the user.

Thanks

    ErrorDocument 404 404.php

    is wrong

    ErrorDocument 404 /404.php

    is ok

    consider the position of the directive in the .htaccess, the order matters

    give it a short time to get the new directive on

      If this won't work:
      ErrorDocument 404 /404.php

      ... then the problem must be elsewhere, because what you're doing is exactly what the Apache documentation says to do. And your example works fine on my Apache2 server.

        My initial thought is that the hosting doesn't allow a relative url in the htaccess file, but it appears to be an issue with IE on the PC.

        So I have a htaccess file with:
        ErrorDocument 404 /404.php

        The page is sends the user to is:
        http://www.pixelsumo.com/404.php

        If I go to:
        www.pixelsumo.com/blahblahblah

        I see the typical :
        "The page cannot be found
        The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. " message.

        People I know have tried this on a Mac and it works fine, in Safari, IE etc. It doesn't seem to work on the pc though. It also works in Firefox on PC, so maybe it's just an internet explorer issue?

        Could this be some kind of header information in my 404.php page that I need to add? Or something else in my htaccess.

          Another little update, I found that in Internet Explorer if you go to Tools > Options > Advanced > Browsing, there is an option that says:
          Show friendly HTTP error messages

          This was ticked on my browser by default, as are most peoples, so IE shows its own message rather than transferring to the correct page.

          There must be a way around this so I am going to look into that.

            Right, the error page you show needs to be at least 512 bytes in size, but only things that are displayed on the page, not including hidden php code etc. So, just add padding to the end of the document and it works.

              but only things that are displayed on the page, not including hidden php code etc.

              don't know what you mean...
              I'm using a 404.php including a my php lib from a different file, and a css schema from another too, and it's working

                I've got an external php and css included on mine and it doesn't seem to include it when looking at the file size, only whats in the html. It's not really a problem, I've just added some comments in the html to pad it out a bit.

                  seems a matter of path
                  if your 404.php is displayed and the css is not considered, it's almost sure that's a matter of path

                  including the php into the 404.php I used a full path, referring to the server root (/www/u/user...)

                  including the css file (in the html part of the 404.php page) I used a relative path to webserver root (/...)

                    No, this isn't the issue, all I was saying that Internet Explorer requires the page to be 512 bytes.

                    Yes, anything you include or use (images etc) in the 404 page needs to be an exact path.

                    I'm not having the problem anymore as it now works when I make it bigger than 512 bytes.

                      where did you find that? IE imposing the limit to 512K when reading a 404.php... ?

                      I have some doubt about IE working differently if reading a common page or a 404 page...

                        Do this in Google:
                        "Internet Explorer" ErrorDocument 512 byte

                        http://www.google.com/search?hl=en&ie=UTF-8&q=%22Internet+Explorer%22+ErrorDocument+512+byte

                        Microsoft Internet Explorer (MSIE) will by default ignore server-generated error messages when they are "too small" and substitute its own "friendly" error messages. The size threshold varies depending on the type of error, but in general, if you make your error document greater than 512 bytes, then MSIE will show the server-generated error rather than masking it. http://httpd.apache.org/docs-2.0/mod/core.html

                        and from Microsoft:
                        "Several frequently-seen status codes have "friendly" error messages that Internet Explorer 5.x displays and that effectively mask the actual text message that the server sends. However, these "friendly" error messages are only displayed if the response that is sent to the client is less than a specified threshold. For example, to see the exact text of an HTTP 500 response, the content length must be greater than or equal to 512 bytes. "
                        http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807

                          I'm actually using a 404.php page of 96 bytes (< 512 bytes), that's including a core php script of 8690 bytes, that's including a php lib of 53100 byte. At the end a html page of 1180 bytes is downloaded to the client + an additional css file of 570 bytes: so, IE on the client is requested to read a total of 1750 bytes (> 512 bytes). My IE does that job with no cry, with the Friendly Error Messages flag checked as usual.

                          From that, here you see that compliancy to the 512 bytes rule (event if I didn't know) is supported by the page downloaded to the client, not else...
                          ...so I still do not understand why your php include is not considered at server side... but for some other issues!

                            Write a Reply...