php 尝试使用 ErrorDocument 处理请求时出现 500 内部服务器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20752140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
500 Internal Server Error when trying to use ErrorDocument to handle request
提问by
I have this .htaccess file:
我有这个 .htaccess 文件:
Options -Indexes
RewriteEngine on
ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]*)/?(.*)$ ./.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.
采纳答案by anubhava
You're most likely getting 500 due to looping error.
由于循环错误,您很可能会得到 500。
Exclude 404.phpfrom 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 ^([^/]+)/?(.*)$ ./.php [L]
回答by nl-x
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 日志文件?
回答by user4483327
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
杰杰
回答by Nidhi
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

