我编辑了我的htaccess文件,将mysite.com/page
重写为mysite.com/page.php
,并在用户请求mysite.com/page.php
代替mysite.com/page
时显示404错误页面
我还添加了自己的自定义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/
时,会显示自定义错误页面(请注意斜杠)。
答案 0 :(得分:1)
我不明白,这个错误来自哪里。但是,您可以在请求RewriteRule ^error/404.php$ - [L]
时退出规则链来解决此问题。在开头插入此规则
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
RewriteCond %{THE_REQUEST} \.php
RewriteRule \.php$ - [L,R=404]
无关,但您可以稍微简化一下规则
{{1}}
答案 1 :(得分:0)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php
ErrorDocument 404 /error/404.php