首页 > 解决方案 > PHP页面中重定向404页面的代码可以放在哪里?

问题描述

如果在重定向期间找不到页面但不知道在 php 文件中的何处应用此代码,例如在我的 php 主页的哪个标签中,我得到了用于重定向 404 错误的正确代码?因为当我将它放在顶部时,它会直接显示 404.php 页面,如果我将它放入 html 中,它会显示标签错误

<?php
http_response_code(404);
include('404.php');
die();

标签: phphtmlhttp-status-code-404

解决方案


Normaly 服务器为未找到的页面添加 404 页面,.shtml或者.html您最好编辑该文件并将此代码添加到您的 htaccess 文件中:

ErrorDocument 404 http://yourdomain.com/404.php.shtml.html


推荐阅读