search

Home  >  Q&A  >  body text

Custom error document 404 page breaks in PHP extension, but works for everything else

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

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

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粉237689596P粉237689596316 days ago349

reply all(1)I'll reply

  • P粉916760429

    P粉9167604292024-01-17 11:42:51

    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]

    reply
    0
  • Cancelreply