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

时间:2021-03-10 15:39:26

I have this .htaccess file:

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

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

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

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.

4 个解决方案

#1


5  

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

由于循环错误,您最有可能获得500。

Exclude 404.php from last rule as:

从上一个规则中排除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]

#2


3  

is 404.php actually set in the root of your filesystem?

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

I'm guessing not.

我猜不是。

Try something like ../404.php

尝试像../404.php这样的东西

BTW: Did you look in your apache log files?

顺便说一下:你看过你的apache日志文件了吗?

#3


0  

Since you want to hide .php extension in your pages, try to remove that extension from the .htaccess file by doing the following:

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

Change: ErrorDocument 404 /404.php to ErrorDocument 404 /404

更改:ErrorDocument 404 /404.php到ErrorDocument 404/404

Hope this helps.

希望这可以帮助。

JJ

JJ

#4


0  

You just Add this code in your .htaccess file

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

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

#1


5  

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

由于循环错误,您最有可能获得500。

Exclude 404.php from last rule as:

从上一个规则中排除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]

#2


3  

is 404.php actually set in the root of your filesystem?

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

I'm guessing not.

我猜不是。

Try something like ../404.php

尝试像../404.php这样的东西

BTW: Did you look in your apache log files?

顺便说一下:你看过你的apache日志文件了吗?

#3


0  

Since you want to hide .php extension in your pages, try to remove that extension from the .htaccess file by doing the following:

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

Change: ErrorDocument 404 /404.php to ErrorDocument 404 /404

更改:ErrorDocument 404 /404.php到ErrorDocument 404/404

Hope this helps.

希望这可以帮助。

JJ

JJ

#4


0  

You just Add this code in your .htaccess file

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

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