Custom error document 404 page breaks in PHP extension, but works for everything else
P粉237689596
P粉237689596 2024-01-16 15:02:40
0
1
328

Updated on 08/02/2022

I have set up a custom 404 error page. Below are my htaccess rules.

ErrorDocument 404 /not-found.php

RewriteEngine On

After many tests, I realized that it works perfectly for everything except php pages. It works fine if the wrong directory or other file extension is accessed.

Example of link successfully displayed on custom 404 error page

  • 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

Example of link that cannot be displayed on custom 404 error page

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

I thought it might be some rewrite rules in my htaccess that were causing the problem, but for testing purposes I've removed them completely and the problem still persists.

P粉237689596
P粉237689596

reply all(1)
P粉916760429

I finally found another person who had the same problem and the solution provided solved my problem. This is the question post

The custom 404 error handler in htaccess does not work for non-existent ".php" files

Here is the solution to make the php extension work:

# 强制对不存在的“.php”请求返回404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!