• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

Issue Custom error pages not working from PHP

IanTLS

New Pleskian
I've set up Custom Error Pages through Plesk. Initially this was all working perfectly, however since then we've migrated to a new server, and now they're not working quite right.

If I trigger an error page through .htaccess e.g.

Code:
RewriteRule ^foo$ - [R=405,NC,L]

This works perfectly and we see our custom error page. However, if I trigger it from PHP e.g.

Code:
http_response_code(405);

Then we just get a standard 405 error, NOT our custom error page. Previously this did work, but at some point in the last few months (possibly when migrating servers) it has stopped.

The site in question is running PHP-FPM 8.2 through Apache on Plesk Obsidian 18.0.62
 
I have a similar issue with custom error pages, I followed this article on the link below to solve it. I added the Additional nginx directives

 
I have a similar issue with custom error pages, I followed this article on the link below to solve it. I added the Additional nginx directives

The site is running with Proxy Mode turned on, and PHP-FPM through Apache, so in theory those nginx directives shouldn't be needed. I went ahead and tried anyway, with no effect.

I've also tried a bunch of different permutations based on that link. I think every combination of:

- Custom errors turned on or off
- Manually entering the Apache directives (including changing to a different folder - the custom_error_pages examples)
- Manually entering the Nginx directives (including changing to a different folder - the custom_error_pages examples)

Easy to get the 404 working (i.e. the one that pops up when I type a random URL), but no scenarios where my custom pages worked from http_response_code().

I've also tried on a different domain/subscription just in case, same symptoms
 
My site was running using PHP-FPM Nginx .... and I have to place the corresponding files in
/var/www/vhosts/domain.com/error_docs/.

For example, the custom404 error page I created "404/index.html", should be moved to /var/www/vhosts/domain.com/error_docs/not_found.html:

cp /var/www/vhosts/domain.com/httpdocs/out/404/index.html /var/www/vhosts/domain.com/error_docs/not_found.html


Could you try change your site to Nginx if possible and move your custom 405 page to "/error_docs/method_not_allowed.html"; and test to see if it loads.

Hope this helps!
 
Could you try change your site to Nginx if possible and move your custom 405 page to "/error_docs/method_not_allowed.html"; and test to see if it loads.
Yes I've got the files in the default /var/www/vhosts/domain.com/error_docs/ folder (but have also tried popping them in a separate folder)

I can't change the site itself to be served by Nginx as we're dependent on .htaccess. I could rebuild those rules in Nginx, but the change control process with the particular customer makes that tricky...
 
Back
Top