Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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
share|improve this answer
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

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:

  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.

share|improve this answer
Setting the header (again) is redundant, but it won't "trigger a further 404 server error". – w3dk Feb 10 '13 at 11:43
Whilst this might be a useful tip, it doesn't actually help answer the OP's question. – w3dk 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
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 posting your answer, you agree to the privacy policy and terms of service.