自定义错误文档404页在PHP扩展中失效,但对其他所有内容有效
P粉237689596
P粉237689596 2024-01-16 15:02:40
0
1
282

更新于08/02/2022

我已经设置了一个自定义的404错误页面。以下是我的htaccess规则。

ErrorDocument 404 /not-found.php

RewriteEngine On

经过多次测试,我意识到它对除php页面以外的所有内容都能完美运行。如果是访问错误的目录或其他文件扩展名,它都可以正常工作。

自定义404错误页面成功显示的链接示例

  • https://www.example.com/bad-file.html
  • https://www.example.com/bad-folder/bad-file.html
  • https://www.example.com/bad-folder/bad-file.php
  • https://www.example.com/existing-folder/bad-file.html
  • https://www.example.com/existing-folder/bad-image.jpg

自定义404错误页面无法显示的链接示例

  • https://www.example.com/bad-file.php
  • https://www.example.com/existing-folder/bad-file.php

我以为可能是我的htaccess中的一些重写规则导致的问题,但为了测试目的,我已经完全删除了它们,但问题仍然存在。

P粉237689596
P粉237689596

全部回复(1)
P粉916760429

我终于找到了另一个遇到同样问题的人,并且提供的解决方案解决了我的问题。这是问题的帖子

htaccess中自定义的404错误处理程序对不存在的“.php”文件不起作用

这是使php扩展工作的解决方案:

# 强制对不存在的“.php”请求返回404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!