Reputation: 200
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/
Upvotes: 6
Views: 26436
Reputation: 15
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.
Upvotes: 0
Reputation: 11
Open Your htaccess and insert this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html
Upvotes: 0
Reputation: 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
Upvotes: -1
Reputation: 1
You can try this code in 404.php in which you can create your own error page...
<?php header('Location: /directory/page-name/'); ?>
Upvotes: 0
Reputation: 923
You can always use the method http_response_code(int code)
.
Here is the method documentation.
Upvotes: 0
Reputation: 1
you can also use below to make all 404 requrest redirect to specific page
FallbackResource /index.html
Upvotes: 0
Reputation: 3877
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
Upvotes: 1
Reputation: 448
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
Upvotes: 3
Reputation: 2001
ErrorDocument 404 http://example.com/404/
add this line to htaccess and change the url
Upvotes: 5