OK, I (and several others) have been encountering strange behaviour when trying to access a known missing page on my site. I have spent several hours researching what exactly is happening and I've even waded through some of the code to see if I can find the issue. Unfortunately I can't. I firmly believe this is a bug within WordPress and I'd appreciate knowing how to bring this to the attention of the developers if posting in here isn't enough.
When the 404.php template is called to announce a missing page in a friendly manner you actually get what looks like utter garbage. It is in fact the output of 404.php, but it is missing the first 10000 or so characters. Thus what you see is raw HTML. This only happens when you are using permalinks. The exact number of characters missing depends on which form of permalinks is being used, but it is always the same number whenever the page is called with the same permalink system.
What I've done to trace the error
- Copied 404.php over page.php and verified that the code does do what it should.
- Added sufficient text to 404.php so that I could be sure that it is actually being used.
- Found the point within 404.php where output starts and copied the first few lines (before my spurious text) to that point. This now displayed a basic page without any CSS formatting.
- Took out the call to get_header() and replaced it with the contents of header.php. This actually worked!!!
I have a file that appears to work with my chosen permalink structure, but it contains an awful lot of garbage. As long as I don't encounter problems with further testing then I'm happy, but, I feel it really ought to be fixed properly. Let me know if you (ie a developer) wants any further information.