SOLVED Custom 404 shows “File not found” for php files instead of redirecting

monkey64

Well-Known Member
Nov 6, 2011
124
5
68
cPanel Access Level
Root Administrator
I am running PHP-FPM on WHM v72.05 with up to date software. I have a custom error page and I am having issues with the Apache ErrorDocument directive. I have the following in my .htaccess file

Code:
RewriteEngine On
ErrorDocument 404 /error.php
I am expecting the user to be directed to my error.php whenever the web page can't be found. If I access the following pages (which do not exist), Apache correctly redirects the user to the error.php page

/a_page_which_does_not_exist
/a_page_which_does_not_exist.html
/a_page_which_does_not_exist.abc

However, when I try to access a file with a .php extension that does not exist I get a blank page with the text "File not found. " I am expecting the user to be directed to error.php. I have tried the following:

Code:
RewriteEngine On
ErrorDocument 404 /[Full Path To User]/error.php
and

Code:
RewriteEngine On
ErrorDocument 404 "some text"
but I still get the File not found text.
My error page has to be a php file raher than a shtml file because it has specific server-side functionality. This used to work perfectly and I can only think that the change to PHP-FPM somehow changed this behaviour.

Can anyone help?
 

monkey64

Well-Known Member
Nov 6, 2011
124
5
68
cPanel Access Level
Root Administrator
Fixed it in the end by adding the following to the Post VirtualHost Include of the Apache Configuration Include Editor:

Code:
Post VirtualHost Include
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,270
463
Hello @monkey64,

I'm glad to see you were able to solve the issue. It looks like the entry in your code is missing. Can you confirm the code you used for the Post VirtualHost Include field?

Thank you.
 

monkey64

Well-Known Member
Nov 6, 2011
124
5
68
cPanel Access Level
Root Administrator
Please ignore my previous post because I did not enter the correct code. Fixed it in the end by adding the following to the Post VirtualHost Include of the Apache Configuration Include Editor:

Code:
ProxyErrorOverride On
 

PeteS

Well-Known Member
Jun 8, 2017
390
88
78
Oregon
cPanel Access Level
Root Administrator
Please ignore my previous post because I did not enter the correct code. Fixed it in the end by adding the following to the Post VirtualHost Include of the Apache Configuration Include Editor:

Code:
ProxyErrorOverride On
FWIW

I have been dealing with this in another thread and you might be interested in this post by cPREX: SOLVED - "File not found." instead of custom 404 file with php-fpm enabled

The method you and I used breaks Webmail, and is not recommended (for other non-descript reasons). There is an include for the individual vhost file but cPREX reports is it currently broken, and he opened a case for it.
 
  • Like
Reactions: cPRex