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/
htacces 应该看起来像
ErrorDocument 404 /page404.php
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
ErrorDocument 404 http://example.com/404/
将此行添加到 htaccess 并更改 url
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
调用函数:
http_send_status(404);
您还可以在下面使用将所有 404 请求重定向到特定页面
FallbackResource /index.html
You can always use the method http_response_code(int code)
. Here is the method documentation.
您可以在 404.php 中尝试此代码,您可以在其中创建自己的错误页面...
<?php header('Location: /directory/page-name/'); ?>
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.