php - 尝试使用 ErrorDocument 处理请求时出现 500 Internal Server Error

标签 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]

但是,当我转到 localhost/example.php 时,它返回 500 Internal Server Error。

有什么帮助吗?谢谢。

编辑:

出现的完整错误信息是:

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]

关于php - 尝试使用 ErrorDocument 处理请求时出现 500 Internal Server Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20752140/

相关文章:

apache - .htaccess 文件不工作

javascript - 尝试使子域作为无 Cookie 域工作

php - 将sql查询放入php函数中

java - 如果定界符出现在给定索引之后,则仅根据定界符在 Java 中拆分字符串一次

javascript - 使用区分大小写字符的正则表达式拆分字符串上的名称

python - 如何解决: Truncated or oversized response headers received from daemon process

php - “授权” header 与请求一起发送,但在 apache_request_headers() 中丢失

php - 美元符号旁边的抓取数字,可选千位和小数

php - 如何创建 PHP 'Download will begin shortly' 页面?

Java - 用于搜索的正则表达式