自定义错误页面在编辑htaccess后无法加载 [英] Custom error page failed to load after editing htaccess
问题描述
我编辑了htaccess文件,将mysite.com/page
重写为mysite.com/page.php
,并在用户请求mysite.com/page.php
而不是mysite.com/page
时显示404错误页面
I edited my htaccess file to rewrite mysite.com/page
to mysite.com/page.php
and to show 404 error page if a user requested mysite.com/page.php
instead of mysite.com/page
我还添加了自己的自定义404错误页面
I also added my own custom 404 error page
但是当我请求mysite.com/page.php
时,显示的错误页面是Apache默认404错误页面(而不是我的自定义错误页面),并带有其他错误信息:
But when I requested mysite.com/page.php
, the error page shown was Apache default 404 error page (instead of my custom error page), with additional error info:
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文件:
Here is my htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule .* - [L,R=404]
ErrorDocument 404 /error/404
我尝试将上面最后一行中的404更改为404.php,但是自定义错误页面仍未显示..
I have tried changing 404 at the last line above to 404.php but the custom error page still not showing up..
但是,当我请求mysite.com/page/
时,出现了自定义错误页面(请注意斜杠).
However, the custom error page did show up when I requested mysite.com/page/
(notice the slash).
推荐答案
我不明白,此错误来自何处.但是您可以通过在请求404.php
时退出规则链来解决该问题.将此规则插入开头
I don't understand, where this error comes from. But you can resolve it by exiting the rule chain when 404.php
is requested. Insert this rule at the beginning
RewriteRule ^error/404.php$ - [L]
不相关,但是您可以稍微简化一下规则
Unrelated, but you can simplify your rules a little bit
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
RewriteCond %{THE_REQUEST} \.php
RewriteRule \.php$ - [L,R=404]
这篇关于自定义错误页面在编辑htaccess后无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!