5

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/

wovano
  • 4,543
  • 5
  • 22
  • 49
Jaswinder Kaur
  • 190
  • 1
  • 3
  • 10

11 Answers11

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

add this line to htaccess and change the url

ManojGeek
  • 1,977
  • 2
  • 16
  • 23
3

the htacces should look like

ErrorDocument 404 /page404.php
Julio Soares
  • 1,200
  • 8
  • 11
3

Try this in your .htaccess:

ErrorDocument 404 http://jobguide.australianenglishcenter.com/404/

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]

Here,The ErrorDocument redirects all 404s to a specific URL

The Rewrite rules map that URL to your actual 404.php script. The RewriteCond regular expressions can be made more generic if you want, but I think you have to explicitly define all ErrorDocument codes you want to override.

NOTE: Replace

Sumit Pandey
  • 448
  • 2
  • 9
1

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
nithi
  • 3,725
  • 2
  • 20
  • 18
0

call the function :

http_send_status(404);
Mukesh Prajapat
  • 274
  • 2
  • 13
  • 2
    in htaccess file and see given link for more help http://stackoverflow.com/questions/437256/why-wont-my-php-app-send-a-404-error – Mukesh Prajapat Oct 09 '15 at 04:55
  • 2
    use following code in htaccess file ErrorDocument 404 https://www.yourdomainname/404.html # or map them to one error document: # ErrorDocument 404 /404.html – Mukesh Prajapat Oct 09 '15 at 05:14
0

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

FallbackResource /index.html
GYaN
  • 2,327
  • 4
  • 19
  • 39
0

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

Tiago_nes
  • 843
  • 7
  • 30
0

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

<?php header('Location: /directory/page-name/'); ?>
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

Open Your htaccess and insert this

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 12 '22 at 00:21
0
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
ErrorDocument 404 http://www.yoursite.com/404.php

This works for me. I don't use any CMS, and my website in php too.

cihankaba
  • 7
  • 6
-1

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
Logemann
  • 2,767
  • 33
  • 53