If you're new to website development please check my HTTP the very basics first.
There are times when user tries to visit a page on your website that doesn't exist. When this happens Apache server displays a generic message and status code that can often looks stupid or uninformative.
Using .htaccess configuration file you can display customized messages. We will be using errorDocument directive/instruction to perform redirection.
The basic syntax for errorDocument is ErrorDocument <3-digit-code> <action>. List of status codes can be found here.
First create .htaccess file, and an HTML page where your custom message will be shown. Put both in your server root directory and paste following directive in htaccess file. errorDocument 404 /blog/error.php ofcourse change the path.
To display a message instead of redirecting all you have to do is replace the <action> part with message, message must be in quotes, for example. errorDocument 404 "Sorry mate, this page don exist :("
It's pretty basic if you think about it. If status code is xxx do this, else do nothing.
Also remember that if you're redirecting user to somewhere locally the <action> part will require the path from the document root. If it's an external site the it must be whole valid URL.
You can check apache's site for more details here.