Score:0

How do you set the " ErrorDocument 404 / example.php " code up without running into this error?

mw flag

I have been working on this "ErrorDocument 404 issue" for the afternoon and I have been unable to solve this issue just yet. Can you please help.

I have set up my custom error 404 page and from that I have been trying to link it to any URL that a user miss spells or incorrectly types into the URL slot. I have been using

    ErrorDocument 404 / example.php

to try and link the users to my error 404 page. It has been acting very weird as I have experienced it only working under certain conditions... As listed below

  1. It only works when the actual name of the file is used rather than the new one we created for it... https://www.mywebsite.com/FileName.php (It returns error 404 with the correct error 404 page)
  2. When it has more than one "/" in the part of the URL after the name of the website... ei: https://www.mywebsite.com/File/Wrong_Page/ (it returns Error page 404)

But when I try anything else it just returns the standard error message of "File not found" with a blank page. Anything other than the examples given above... Does not work at all!

How can I fix this so that my website will always display the error 404 page instead of the default file not found page or error page of the Search Engine?

HBruijn avatar
in flag
Welcome to Server Fault! Please use copy-paste for settings and format that text as "`code`" using [Markdown](https://serverfault.com/editing-help) and/or the formatting options in the edit menu to properly type-set your posts. - If you really have and [`ErrorDocument`](https://httpd.apache.org/docs/2.4/mod/core.html#errordocument) space `404` space `/` space `example.php` that seems like a misconfiguration (there shouldn't be a space between `/ example.php` - note that some browsers (used to) display their own, rather than your custom, error page, when the custom page is too simple
djdomi avatar
za flag
welcome Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers., as also verify [ask]
Mathew avatar
mw flag
Hi @HBruijn. I hope that I have done everything correctly to what you have told me to do? No matter where I have the code as "`ErrorDocument 404 / example.php` or `ErrorDocument 404 example.php` or even without the `.php` as we have coded our website to remove the `.php` from the URL to make them neater"
kz flag
You have an erroneous _space_ in the directive you've posted. It should be `ErrorDocument 404 /example.php`, not `ErrorDocument 404 / example.php`. Are you behind a front-end proxy? What other directives do you have in your `.htaccess` file? "...rather than the new one we created for it" - what do you mean by that? Are you rewriting the request? Or is this managed by your application??
Mathew avatar
mw flag
Hi @MrWhite I have tried removing the space, removing the "/", removing the ".php"... nothing is working properly, I went on and searched online some more and found code that said `ProxyErrorOverride On` and that broke the server.. For the front-end proxy, I dont have one. " "...rather than the new one we created for it" - what do you mean by that?" For this I mean that I have rewritten the names of the pages, firstly to neaten them up and also to remove the file type from the name, ei: "`.php`". I am also not using any application, The website is hard coded
Mathew avatar
mw flag
Hi @MrWhite, This is what I have used to try and get the Error 404 pages to be redirected to my custom page `RewriteCond %{THE_REQUEST} /404-not-found\.php [NC]` `RewriteRule ^ - [R=404,L]` `RewriteCond %{REQUEST_FILENAME} !-d` `RewriteCond %{REQUEST_FILENAME}\.php -f` `RewriteRule ^404-not-found 404-not-found.php [NC,L]` `ErrorDocument 404 /404-not-found/`
Score:0
cu flag

Check that the "mod_rewrite" module is enabled in your Apache configuration and ensure that the "AllowOverride" directive is set to "All" for the directory where your .htaccess file resides.

Score:0
cd flag

There may be something wrong with your htaccess in another line.

I recommend running a htaccess syntax validator like htaccesscheck

That should tell you something.

This is the correct syntax to customize an Error 404 page:

ErrorDocument 404 /error-page.php

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.