尝试使用ErrorDocument处理请求时发生500内部服务器错误(500 Internal Server Error when trying to use ErrorDocument to han

编程入门 行业动态 更新时间:2024-10-22 21:17:24
尝试使用ErrorDocument处理请求时发生500内部服务器错误(500 Internal Server Error when trying to use ErrorDocument to handle request)

我有这个.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.

I have this .htaccess file:

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]

However, when I go to localhost/example.php, it returns a 500 Internal Server Error.

Any help please? Thanks.

EDIT:

The full error message that comes up is:

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]

You're most likely getting 500 due to looping error.

Exclude 404.php from last rule as:

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]

更多推荐

本文发布于:2023-04-29 09:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   发生   服务器   ErrorDocument   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!