Skip to main content

"File not found" appears instead of 404.shtml (easy htaccess solution)

Comments

3 comments

  • cPanelMichael
    Hello John, I removed the previous posts to this thread as there appears to have been some confusion about the question you were asking.
    What is wrong with this simple .htaccess fix? # High up in the .htaccess file. ErrorDocument 404 /404.shtml # After your last rewrite rule. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteRule ^.+\.php$ /404 [NC,L] The above works for me without any Apache changes.

    "Why is ProxyErrorOverride On better than my htaccess method?"

    You can setup the rules via your .htaccess file or via a custom Apache include. Using a .htaccess file is actually less likely to result in issues with Service Subdomains (e.g. webmail.domain.tld) per the discussion on the thread below: Thus, I don't believe using a custom Apache include is better than the method you provided. Let me know if that helps to clarify. Thank you.
    0
  • John Napoletano
    Hello John, I removed the previous posts to this thread as there appears to have been some confusion about the question you were asking. You can setup the rules via your .htaccess file or via a custom Apache include. Using a .htaccess file is actually less likely to result in issues with Service Subdomains (e.g. webmail.domain.tld) per the discussion on the thread below: Thus, I don't believe using a custom Apache include is better than the method you provided. Let me know if that helps to clarify. Thank you.

    @cPanelMichael Thank you for clarifying. There was also a piece of the puzzle relating to log errors such as this one: mod_include: Options +Includes (or IncludesNoExec) wasn't set, INCLUDES filter removed: /404.shtml There are settings for these options, checkboxes, accessible from WHM. Ultimately my problem in regards to the log errors, I believe was that I first disabled all 'Options' using htaccess, then forgot to add back the option as indicated by the log error. Here is the snippet of the htaccess related to the mod_include error if that helps anyone. If it's confusing then post here and I'll try to clarify. It's not fresh in my mind at the moment. # Options Options None Options +SymLinksIfOwnerMatch +IncludesNOEXEC -Indexes The mod_include log error stopped appearing after making the above change with the +IncludesNOEXEC being the piece that I was missing per the error message. Putting it all together would include the following lines in my htaccess, other lines left out to simplify: # High up in the .htaccess file. Options None Options +SymLinksIfOwnerMatch +IncludesNOEXEC -Indexes ErrorDocument 404 /404.shtml # After your last rewrite rule. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteRule ^.+\.php$ /404 [NC,L]
    0
  • Arty2
    "File not found" simple error message text appears instead of a custom 404.shtml file whenever a .php extension such as /not-a-file.php targeted. Non .php files work as expected on error such as /not-a-file.html for example. I spent a couple of hours messing around with Apache and htaccess settings trying to sort this out. I just migrated to a new server, always fun :( The forums here show several posts that didn't appear to help such as ProxyErrorOverride On. What is wrong with this simple .htaccess fix? # High up in the .htaccess file. ErrorDocument 404 /404.shtml # After your last rewrite rule. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteRule ^.+\.php$ /404 [NC,L] The above works for me without any Apache changes. Beware there is an similar rule out that that throws a 200 status instead of a 404 very important. Ensure you get a 404 upon inspection in F12 Google Chrome for example. Any insight would be appreciated.

    Could you just share fix I don't have coding experience
    0

Please sign in to leave a comment.