Apache Subdirectory 404 for missing template includes?
JAB Creations
10:46 pm on Aug 4, 2007 (gmt 0)
I have created my own PHP template system and pull templates from...
templates/
In one example have a home directory that pulls the content from the templates directory.
I'd like to have Apache use a specific 404 missing template file if the requested template is not found. How do I do this?
- John
jdMorgan
1:04 am on Aug 5, 2007 (gmt 0)
If your script is including the template by reading it from the filesystem, then Apache won't be aware of the success or failure of that file access. Apache would be aware of it if the script used an HTTP GET to fetch the template using HTTP, but that would be horribly inefficient...
Really, all you can do is handle the error by
Throwing a script error, resulting in a 500-Server Error (very ugly) - or -
Handling the error inside the script -- output an error message to the client (fairly ugly) - or -
Using a default template to avoid the error, - and then -
have the script send you an e-mail telling you to go fix the problem - or -
have the script open a custom error log file, and write a message to it for you to check periodically Jim
JAB Creations
3:43 am on Aug 5, 2007 (gmt 0)
It's a PHP includes....
So if a file wasn't found couldn't we do a special "use this file instead if a requested file isn't found in this directory"?
- John
jdMorgan
3:52 am on Aug 5, 2007 (gmt 0)
Yes, of course. My point is that this function of "template not found -- use this other file" is part of the script itself, and Apache isn't involved unless the script actually crashes or exits unexpectedly because of the missing file.
A 404 error is the result of a failed HTTP request, and a PHP "file include" uses an operating system file system read function, not an HTTP request, to get the file.