Got Custom 404 Page?
I am surprised at how many websites do not have custom 404 pages.
Try entering a nonexistent web page for your website.
And what is a custom 404 page? A response to a web page not found. If a web page is not found on your site, the server returns a 404 error. Normally the web host has a default web page in response to a 404 error. Most web hosts allow a custom 404 page which you can put just about anything you want on it. And a link to the homepage can be put on; something a default 404 page does not have.
Check with your web host on how to redirect a 404 to your custom 404 page. Each host has its own peculiarities.
The .htaccess file can be modified to point to a custom 404 page (note .htaccess file is only for Apache servers). Add the following line:
ErrorDocument 404 http://www.mydomain.com/404-error-page.php
Replace mydomain with your domain. Note the error page can be an html file instead of a php file. This worked fine if the error page was an html page but did not work if it was a php page.
A better way is this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.htm
where /errordocument.htm is the custom 404 page for your site. This can also be a php script such as custom404.php. Note this goes in the root directory. Just add directories like this: /dir1/dir2/errordocument.php
This method worked fine for nonexistent html and php pages.
Doug