Context: Apache + PHP-FPM. Migrated a website to a new server. 404s stopped working. Instead of redirecting to a custom page, 404 errors now show the text "File not found."
Expectations: https://nobleme.com/404
Reality: https://nobleme.com/notapage
My .htaccess used to work on my previous server with the following directive (which I haven't touched):
RewriteEngine On
ErrorDocument 404 https://nobleme.com/404
I have tried including the following directive both in my httpd.conf and my website.conf, but to no avail:
ProxyErrorOverride On
The only notable difference between my previous server and the current one is usage of PHP-FPM, so it might be a related issue. Any pointers on how to solve this would be much appreciated.
Solved it myself.
ProxyErrorOverride
is a terrible idea, don't do that.
Instead edit your /etc/httpd/conf.d/php.conf
Look for SetHandler
And add a condition that the file must exist before the handling happens
Then reboot your apache to update the configuration
Here's an example of that section of my php.conf:
<FilesMatch \.(php|phar)$>
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</If>
</FilesMatch>
Hope this helps someone in the future.