How can I redirect to or render an invalid page in my website if the user tries to type wrong URL which is doesn't exist. I want a common code for this as I don't used framework in website so that If a user type in action that is wrong or does not exists will redirect to page saying " The page isn't available"? I have not used any framework in my Website. So Please Give me a solution.
If you set up your .htaccess file, you can define a custom 404 error page.
You can follow this tutorial :https://www.digitalocean.com/community/tutorials/how-to-create-a-custom-404-page-in-apache
Create a a 404.php page then write what ever you want em to see then create a .htaccess file place it on the same folder as your site
404.php
<?php
header("HTTP/1.0 404 Not Found");
?>
<html>
<head>
<title>404 Error - Page Not Found</title>
</head>
<body>404 Error - Page Not Found!</body>
</html>
You must specify the 404 HTTP response header in your custom 404 error page else it would be treated as a normal page and 200 OK response will be sent to client browser. The
header()
must be called before any actual output is sent
.htaccess
ErrorDocument 404 /404.php