Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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". –  w3d Feb 10 '13 at 11:43
@w3d - Yeah, poor choice of words, I should've written 'add a response header indicating 404 error'... which was obviously already included in the server's response. –  TildalWave Feb 10 '13 at 12:09
Whilst this might be a useful tip, it doesn't actually help answer the OP's question. –  w3d Feb 10 '13 at 13:20
@w3d - Yeah, I got stuck on some other SE pages, sorry about that... wanted to come back later when I had more time (OP didn't come back since posting this question anyway), but got beaten to the punch by Stephen, and I don't see any reason why I'd dupe his post, it's spot on as far as I can tell and a +1 from me. I'm leaving my 'answer' though, as it's still relevant to OP's example code, albeit it doesn't answer the question, true that. ;) –  TildalWave Feb 10 '13 at 13:26
Ok, I removed the code and it sends a 404 header and everything works. Thanks! –  user20525 Feb 14 '13 at 5:02
show 1 more comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.