I have a .htaccess
file in the root directory and also 404.php file there. Content of my .htaccess
file is:
ErrorDocument 404 /404.php
But when I am mis-spelling my url, 404.php
is not opening. Instead I am getting following message:
Not Found
The requested URL /mywebsite/ites.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
But when I tried ErrorDocument 404 google.com
, it worked.
Where is your
404.php
actually located in relation to your.htaccess
file? Can you simply run it as a direct URL? Is the file readable by the server? Or is it in a nested subdirectory? You can also try the full URL as well:Full details in the official Apache documentation here.
I'll consolidate my comments to this answer:
When setting ...
the
/404.php
path may not be the absolute path to your htdocs folder root but instead the root of your filesystem. This may be, based on your configuration, e.g./home/htdocs/
or~
and so on.So what one need to do is find out the absolute path and set it accordingly.
You use ErrorDocument like so:
ErrorDocument <3-digit-code> <action>
You have three types of action that are triggered by what you type:
The the action will be treated as:
Eg.
Custom text:
ErrorDocument 404 "Oops! We can't find that pesky file. Sorry."
Local path:
ErrorDocument 404 /local/path/to/404.php
External URL:
ErrorDocument 404 http://external_url.example.com/server_error.html
You've chosen a local file, but are probably not linking correctly from the server's perspective. Local server paths are not what you see in your URL, and often include things like
~/htdocs/www/domainname/
.The problem is most likely that your path to
404.php
is wrong, and cannot be found by your server.