'How to redirect 404 error to 404.php page?

I need help in php. I am making one portal website in Core Php. I had created 404 page and .htaccess file.

404.php:

<html>
  <head>
    <title>404 Error - Page Not Found</title>
  </head>
  <body>404 Error - Page Not Found!</body>
</html>

.htaccess:

Redirect 404 /404.php 

But this is not working. If I use this code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.html [L]
</IfModule>

It shows internal server error.

Here is my website: http://jobguide.australianenglishcenter.com/

php


Solution 1:[1]

ErrorDocument 404 http://example.com/404/

add this line to htaccess and change the url

Solution 2:[2]

the htacces should look like

ErrorDocument 404 /page404.php

Solution 3:[3]

You have to set the rewrite engine on. Then customize a php page to handle the 404 error. Refer the below code

RewriteEngine on
ErrorDocument 404 http://www.example.com/your-404-custom-file-name.php

Solution 4:[4]

call the function :

http_send_status(404);

Solution 5:[5]

you can also use below to make all 404 requrest redirect to specific page

FallbackResource /index.html

Solution 6:[6]

You can always use the method http_response_code(int code). Here is the method documentation.

Solution 7:[7]

You can try this code in 404.php in which you can create your own error page...

<?php header('Location: /directory/page-name/'); ?>

Solution 8:[8]

Open Your htaccess and insert this

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html

Solution 9:[9]

I think a simple way to add a 404, 505, or other pages in your project just put the simple thing in your .htaccess file which is in the project root folder and paste the simple line

RewriteEngine on
errordocument 404 http://localhost/MVC_Project2/404.php

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ManojGeek
Solution 2 Julio Soares
Solution 3 nithi
Solution 4 Mukesh Prajapat
Solution 5 GYaN
Solution 6 Tiago_nes
Solution 7 Cody Gray
Solution 8
Solution 9 Logemann