How to redirect WordPress 404 page through function()

The following code will return “ugly” page like this:

Since we have our own 404 page, why not we use it? Add the following code to redirect it to our theme 404 page.

and now for security reason, whoever request to the restricted page will get our beautiful 404 page.