php - PHP页面中重定向404页面的代码可以放在哪里?
问题描述
如果在重定向期间找不到页面但不知道在 php 文件中的何处应用此代码,例如在我的 php 主页的哪个标签中,我得到了用于重定向 404 错误的正确代码?因为当我将它放在顶部时,它会直接显示 404.php 页面,如果我将它放入 html 中,它会显示标签错误
<?php
http_response_code(404);
include('404.php');
die();
解决方案
Normaly 服务器为未找到的页面添加 404 页面,.shtml
或者.html
您最好编辑该文件并将此代码添加到您的 htaccess 文件中:
ErrorDocument 404 http://yourdomain.com/404.php
或.shtml
或.html
推荐阅读
- python - Tkinter 从剪贴板将图像粘贴到文本框中
- google-chrome - Selenium 是否支持在无头浏览器上拖动 / ClickAndHold?
- python - PyCharm 2018.1.4 看不到课程?
- node.js - 用于nodejs应用程序的nginx plesk的499错误代码
- python - 如何计算每小时出现的不同值?
- regex - 在子字符串正则表达式中查找字符串
- elasticsearch - QueryDSL _id 查询脚本内
- sql-server - SQL Server:如何从每个组中获取前“N”个最大出现次数
- javascript - 如何创建每个循环,但将数据保持在一起
- javascript - Javascript 确认在 chrome 中立即关闭