500 内部服务器 尝试使用错误文档处理请求时出错



我有这个.htaccess文件:

Options -Indexes
RewriteEngine on
ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]*)/?(.*)$ ./$1.php
RewriteCond %{THE_REQUEST} .php
RewriteRule ^(.*)$ - [L,R=404]

但是,当我转到 localhost/example.php 时,它返回 500 内部服务器错误。

请帮忙吗?谢谢。

编辑:

出现的完整错误消息是:

Not Found
The requested URL /example.php was not found on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

由于循环错误,您很可能会得到 500。

从上一条规则中排除404.php为:

ErrorDocument 404 /404.php
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} .php [NC]
RewriteRule ^(?!404.php)$ - [L,NC,R=404]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/?(.*)$ ./$1.php [L]

404.php 实际上是在文件系统的根目录中设置的吗?

我猜不是。

尝试类似../404.php

BTW:你看过你的apache日志文件吗?

您只需将此代码添加到 .htaccess 文件中即可

# BEGING WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

由于您要在页面中隐藏.php扩展名,请尝试通过执行以下操作从 .htaccess 文件中删除该扩展名:

更改:错误文档 404/404.php 更改为错误文档 404/404

希望这有帮助。

我遇到了这个问题。但是我的错误是服务器的磁盘已满100%。您应该检查服务器磁盘,作为考虑的解决方案。

最新更新