PHP页面的404重定向代码应该放在哪里?
Where can I place the code for redirecting 404 page in the PHP page?
如果在重定向期间找不到页面,我得到了重定向 404 错误的正确代码,但不知道在 php 文件中的何处应用此代码,就像在我的 php 主页的哪个标签中一样页?
因为当我要将它放在顶部时,它会直接显示 404.php 页面,如果我将它放在 html 中,它会显示标记错误
<?php
http_response_code(404);
include('404.php');
die();
通常服务器会为 .shtml
或 .html
中未找到的页面添加 404 页面,您最好编辑该文件
并将此代码添加到您的 htaccess 文件中:
ErrorDocument 404 http://yourdomain.com/404.php
或 .shtml
或 .html
通过 .htaccess 中的一行,您可以将用户重定向到您的 404 页面
将此行添加到您的 .htaccess 文件中
错误文档 404 http://YOUR-PATH/404.php
如果在重定向期间找不到页面,我得到了重定向 404 错误的正确代码,但不知道在 php 文件中的何处应用此代码,就像在我的 php 主页的哪个标签中一样页? 因为当我要将它放在顶部时,它会直接显示 404.php 页面,如果我将它放在 html 中,它会显示标记错误
<?php
http_response_code(404);
include('404.php');
die();
通常服务器会为 .shtml
或 .html
中未找到的页面添加 404 页面,您最好编辑该文件
并将此代码添加到您的 htaccess 文件中:
ErrorDocument 404 http://yourdomain.com/404.php
或 .shtml
或 .html
通过 .htaccess 中的一行,您可以将用户重定向到您的 404 页面
将此行添加到您的 .htaccess 文件中 错误文档 404 http://YOUR-PATH/404.php