ErrorDocument not working in .htaccces file

First post. Newly created account. Hope this is the right forum. Do not want to duplicate post.

ErrorDocument not working in .htaccces file

Do not have wordpress or any other apps installed except what was installed when the website was created.

Trying to create a custom ErrorDocument in PHP.

This is the errordocument code in my .htaccess file (only one line is NOT commented out at a time). Currently it is:

###ErrorDocument 404 "From .htaccess - This is a custom 404 error page done with ErrorDocument in .htaccess"
###ErrorDocument 404 /404.html
ErrorDocument 404 /404.php

The literal, and the php will not work (will display the HTML 404 error page)
The html works right (will display the text from the html file)
If I execute the php version as a url in the browser it will display the error message - so it is not the code.
https://domainfwd.000webhostapp.com/404.php

For a test you can use the following
This will be found
https://domainfwd.000webhostapp.com/a.txt

This will not be found and will display the custom error message from HTML 404 error page - not the php page.
https://domainfwd.000webhostapp.com/waileqb.html
https://domainfwd.000webhostapp.com/waileqb.php
https://domainfwd.000webhostapp.com/waileqb.txt

So, my question is — How do I get the php version to work?

This is the code for 404.php

  <?php
  ?>

<!DOCTYPE html>
<html>
  <head>
    </head>
      <body>
        <p>From 404.php - This is a custom 404 error page done with ErrorDocument in .htaccess</p>
      </body>
  </html>

this is the code for 404.html

<!DOCTYPE html>
  <html>
    <head>
   </head>
      <body>
        <p>From 404.html - This is a custom 404 error page done with ErrorDocument in .htaccess</p>
      </body>
  </html>

I don’t know what could be the error but here’s a code that might help aswell.
ErrorDocument 404 “Add code here (ex < h1>file not found )”

tried
ErrorDocument 404 "From .htaccess - This is a custom 404 error page done with ErrorDocument in .htaccess"
but did not work. also displays the 404.html code

hmm this should be a server error.

Why should it be a server error (500?) instead of a 404?

Have a look at this list of error documents you can create html files for(add them to .htaccess):

ErrorDocument 400 <URL of Error Page>
ErrorDocument 401 <URL of Error Page>
ErrorDocument 403 <URL of Error Page>
ErrorDocument 404 <URL of Error Page>
ErrorDocument 500 <URL of Error Page>
ErrorDocument 502 <URL of Error Page>

Note: Please replace <URL of Error Page> with the real URL of the error document.

I did that (see top of first post)
ErrorDocument 404 /404.php

The trouble is that it will not execute the php file. It uses the html file (404.html).
in the first post i show the code for the .htaccess, 404.html, and 404.php along with urls to try.

So, my question is — How do I get the php version to work?

Then enter 404.php instead of 404.html in .htaccess

Hi @George01!

Try this code instead:

ErrorDocument 404 http://domainfwd.000webhostapp.com/404.php 

When it comes to PHP scripts, the .htaccess uses the root of your filesystem (which is definitely not the one from /public_html). To avoid paths complications, please input the coded the way I provided it :wink:

tried the code above (copy and paste) and it still goes to the 404.html instead of 404.php. as an example this will not be found and will display the custom error message from HTML 404 error page - not the php page.
https://domainfwd.000webhostapp.com/waileqb.html

Actually, the codes works perfectly however it interferes with the website builder and the code it sets up in the .htaccess.

Give me a while to find a fix for it…

The main .htaccess from /public_html redirects all traffic to /public_html/zyro. If we change the Zyro code from it, the whole website will not render anymore.

It is pretty difficult to add a ErrorPage directive because of how Zyro publishes the website. The only way I have found to do it is to replace the entire .htaccess from /public_html/zyro with the proper directives and move all 404 files to /public_html/zyro.

However:

  1. This will remove the protection of the other directories from within /zyro folder
  2. The settings will be lost next time you publish the website from Zyro Builder.

Thanks for your help. I will see what I can do with it as it exists.

1 Like

Please post here if you find other solutions :slight_smile: