English 中文(简体)
如何使用购买力平价制造错误404页?
原标题:How to create an error 404 page using PHP?
  • 时间:2009-09-04 19:29:58
  •  标签:

页: 1 处理从<代码>/序号_here到我内部终点的所有要求:/page.php?name=word_here/code>。 然后,如果要求使用的网页上有一页,就进行录音。

如果没有,我如何模拟错误404?

我曾尝试过这一尝试,但并没有产生我404页的定本,该页面是通过ErrorDocument.htaccess上配置的。 显示。

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");

我正确地认为,改用我的错误404页是错误的?

最佳回答
问题回答

你做些什么,浏览器将得到404部法典。 ∗∗∗ 确实显示你可能期望的“没有发现”网页,例如:

Not Found

The requested URL /test. 该服务器上没有发现Sphp。

这是因为,当PHP退回了404部代码(至少是Pharma don t)时,网络服务器就寄出该网页。 PHP负责发送其全部产出。 因此,如果你想要一个类似的网页,你必须寄送超文本,例如:

<?php
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
include("notFound.php");
?>

您可以召集会议。 阿帕奇在自己的404条电文中使用同一页,将其放在httpsd上。 会议:

ErrorDocument 404 /notFound.php

为此:

<?php
header("HTTP/1.0 404 Not Found");
?>

www.un.org/Depts/DGACM/index_spanish.htm 通过号检索文档生成海关错误页。

1, 404 - page not found

 RewriteEngine On
 ErrorDocument 404 /404.html

2 500 - Internal服务器 Error

RewriteEngine On
ErrorDocument 500 /500.html

3,403 - Forbidden

RewriteEngine On
ErrorDocument 403 /403.html

4. 400 - Bad request

RewriteEngine On
ErrorDocument 400 /400.html

5. 401 - 授权要求

RewriteEngine On
ErrorDocument 401 /401.html

www.un.org/Depts/DGACM/index_spanish.htm 您还可以将所有错误转至单页。 见。

RewriteEngine On
ErrorDocument 404 /404.html
ErrorDocument 500 /404.html
ErrorDocument 403 /404.html
ErrorDocument 400 /404.html
ErrorDocument 401 /401.html

你们是否记得在派头脑后死亡? 404名总经理没有自动停止处理,因此,如果进一步处理,似乎不会采取任何行动。

这不利于REDIRECT的404页,但你可以认为INCLUDE的内容没有任何问题。 这样,你有一页,从正确的URL中适当发送404份身份,但你也有“你看什么?”的人读物页。

标准阿帕奇404错误就是这样:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>  

因此,你可以使用以下购买力平价代码制作404页,准确看成标准页404页:

function httpNotFound()
{
    http_response_code(404);
    header( Content-type: text/html );

    // Generate standard apache 404 error page
    echo <<<HTML
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>  
HTML;

    exit;
}

审判

ErrorDocument 404 /(root directory)/(error file) 

<代码>htaccess文档。

不管怎样,用404个错误取代。

在Droupal或Word CMS(以及可能的其他人)中,如果你试图制定某些习俗,则似乎不存在(除非满足某些条件),那么以下工作就好了,使CMS的404名手勒接手:

<?php
  if(condition){
    do stuff;
  } else {
    include( index.php );
  }
?>




相关问题
热门标签