Php 自定义404页面并向其发送用户
因此,我的.htaccess文件如下所示Php 自定义404页面并向其发送用户,php,.htaccess,http-status-code-404,Php,.htaccess,Http Status Code 404,因此,我的.htaccess文件如下所示 <IfModule mod_rewrite.c> Options +FollowSymLinks - MultiViews RewriteEngine on ErrorDocument 404 404.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^/]*)$ $1.php Rewrite
<IfModule mod_rewrite.c>
Options +FollowSymLinks - MultiViews
RewriteEngine on
ErrorDocument 404 404.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ profile.php?username=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ profile.php?username=$1&page=$2 [L]
</IfModule>
但它仍然会加载配置文件,并且不会出现404错误。我试过使用header('Location:index');然后它重定向到索引
要让它生成404,我缺少什么?此响应包含有用的信息,它基本上表示,一旦服务器开始处理您的代码,它将不会显示服务器默认的404页面。尽管它会将响应代码设置为404(用户基本上看不见)。但是,在.htaccess中有404错误转到404.php,所以只需使用
header('Location: /404.php');
指向已设置的404 php页面。要显示404页面而不必重定向到www.example.com/404.php,请执行以下操作:
if ($User == NULL)
{
//this will set the 404 header
header("HTTP/1.0 404 Not Found");
//this will load the 404 page
include '/404.html';
}
else
{
...
}
if ($User == NULL)
{
//this will set the 404 header
header("HTTP/1.0 404 Not Found");
//this will load the 404 page
include '/404.html';
}
else
{
...
}