Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'EasyApache' started by monkey64, Jun 27, 2018.

Tags:
  1. monkey64

    monkey64 Well-Known Member

    Joined:
    Nov 6, 2011
    Messages:
    95
    Likes Received:
    3
    Trophy Points:
    58
    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?
     
  2. monkey64

    monkey64 Well-Known Member

    Joined:
    Nov 6, 2011
    Messages:
    95
    Likes Received:
    3
    Trophy Points:
    58
    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
    
     
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. monkey64

    monkey64 Well-Known Member

    Joined:
    Nov 6, 2011
    Messages:
    95
    Likes Received:
    3
    Trophy Points:
    58
    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
     
  5. cPanelLauren

    cPanelLauren Forums Analyst II
    Staff Member

    Joined:
    Nov 14, 2017
    Messages:
    3,451
    Likes Received:
    246
    Trophy Points:
    173
    Location:
    Houston
    cPanel Access Level:
    DataCenter Provider
    Hi @monkey64

    Thanks for updating the thread with the solution that worked for you! I'll go ahead and mark this as resolved.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice