4

My 404 page (/404.php) works, it's sending the proper headers (404 - Not found).

But the thing is, it's not giving the link that caused it (e.g. example.com/thisisnon-existant.htm) but instead it's giving my 404 page (example.com/404.php).

How would I get it fixed?

All I did was add the following to .htaccess:

ErrorDocument 404 http://example.com/404.php

My 404 page's code is here: http://pastebin.com/G7mQ4aT1.

6

When you use the full url for ErrorDocument, Apache will always issue a redirect to that location. You want to change your ErrorDocument directive to a relative path instead.

ErrorDocument 404 /404.php
1
  • 1
    Oh my gosh, I fell so dumb. Thanks man. I'd never thought to use that because every thing I read said "ALWAYS USE DIRECT PATH, NEVER RELATIVE PATHS"
    – user20525
    Feb 11 '13 at 4:41
3

Stephen answered your question spot on, but another observation regarding your example code that you linked to, that you might want to remove these lines in your PHP code:

<?php
  header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
?>

Your web server already responded with 404 when this document would be used and you're just providing a nicer to read error document. There is no need for this document to add a response header indicating 404 error like you did, when it would already be included in a server's response following a request for non-existent location/document.

4
  • Setting the header (again) is redundant, but it won't "trigger a further 404 server error".
    – MrWhite
    Feb 10 '13 at 11:43
  • Whilst this might be a useful tip, it doesn't actually help answer the OP's question.
    – MrWhite
    Feb 10 '13 at 13:20
  • What was happening it was a soft 404, I didn't want google to see it as a page, so I added that for a temp fix, I'm still testing it.
    – user20525
    Feb 11 '13 at 4:42
  • 1
    Ok, I removed the code and it sends a 404 header and everything works. Thanks!
    – user20525
    Feb 14 '13 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy