Forum Moderators: phranque
I have edited my .htaccess file to point to a custom 404 page by adding
ErrorDocument 404 /404.html
Then i wanted to add a little php code to my site, the navigation menu onto every page, so i added a server side include on each .html page.
Then I researched how to parse .html as php and found i can add
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
It worked, the php appears and i didnt have to rename all my pages .php. Pretty cool, but the custom 404 error page dosent show up in IE8.
If i remove the above code it works again, put it back and i get the defualt IE8 error page. From my limited testing, on two PC's, XP and Vista, and 5 different browsers IE6 & IE8 are affected. Google Chrome, Safari, and Firefox are not affected.
I also use in the .htaccess file
ErrorDocument 403 /403.html
Options -Indexes
And when a browser tries to browse directories it takes them to my custom 403 error page that says forbidden. That function is not affected.
Hope you can help. Thank you in advance.
In the .htaccess file I changed the application/x-httpd-php line to only work for .html. Then i changed the name of the error document to 404.htm.
ErrorDocument 404 /404.htm
AddType application/x-httpd-php .html
It is working.
One more note. Whenever possible, use static files for custom error documents, especially for critical errors like 403, 404, and 500. You want to avoid the situation where a bug in shared (#included) code or a fault in the script interpreter causes an initial error, but the server is unable to handle that error because the error document also uses and requires that same faulty code or interpreter.
This leads to a cascade of errors, a failure to serve the error document, and a very confused visitor (and possibly a confused Webmaster as well).
So, error-handling should be kept as simple and free of dependencies as possible, and "I want to make all my pages use the same template" is not really a very good reason to break this rule.
Think of it this way: For some reason you're in hospital, dependent (temporarily) on a heart/lung machine to sustain your life. You look over, and you see that the machine is running Windows Vista with all of the Aero bells and whistles enabled, even though a simple Linux kernel would have sufficed. Are you happy? Not me... ;)
Jim