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

11 php regex apache .htaccess mod-rewrite

我有这个.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]
Run Code Online (Sandbox Code Playgroud)

但是,当我去时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.
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 5

由于循环错误,您最有可能获得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]
Run Code Online (Sandbox Code Playgroud)