编辑htaccess后,自定义错误页面加载失败


Custom error page failed to load after editing htaccess

我编辑了我的htaccess文件,将mysite.com/page重写为mysite.com/page.php,并显示404错误页面,如果用户请求mysite.com/page.php而不是mysite.com/page

我还添加了自己的自定义404错误页面

但是当我请求mysite.com/page.php时,显示的错误页面是Apache默认的404错误页面(而不是我的自定义错误页面),带有额外的错误信息:

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

我的错误日志:

Request exceeded the limit of 10 internal redirects due to probable configuration error.
这是我的htaccess文件:
RewriteEngine On
RewriteBase /
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
RewriteCond %{THE_REQUEST} "^[^ ]* .*?'.php[? ].*$"
RewriteRule .* - [L,R=404]
ErrorDocument 404 /error/404

我已经尝试在上面的最后一行更改404到404.php,但自定义错误页面仍然没有显示..

然而,当我请求mysite.com/page/(注意斜杠)时,自定义错误页面确实出现了。

我不明白,这个错误是从哪里来的。但是您可以通过在请求404.php时退出规则链来解决这个问题。在

开头插入此规则
RewriteRule ^error/404.php$ - [L]

不相关,但是你可以稍微简化你的规则

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
RewriteCond %{THE_REQUEST} '.php
RewriteRule '.php$ - [L,R=404]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^'.]+)$ $1.php
ErrorDocument 404 /error/404.php