Php 尝试使用ErrorDocument处理请求时出现500内部服务器错误
我有一个.htaccess文件:Php 尝试使用ErrorDocument处理请求时出现500内部服务器错误,php,regex,apache,.htaccess,mod-rewrite,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,
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.
404.php实际上是在文件系统的根目录中设置的吗 我猜不是 试试../404.php之类的东西
顺便说一句:你有没有查看你的apache日志文件 由于循环错误,您很可能得到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扩展名,请尝试通过执行以下操作从.htaccess文件中删除该扩展名: 更改:ErrorDocument 404/404.php为ErrorDocument 404/404 希望这有帮助
JJ您只需将此代码添加到.htaccess文件中
# BEGING WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
这很可能是问题所在,但我认为
。/404.php
不是问题所在appropriate@Phil:请分享404.php在根目录中的位置:(@user3130907是文件系统(硬盘驱动器)的根目录还是网站的根目录?/404.php表示文件系统(硬盘驱动器)的根目录)它存储在www
文件夹中。您尝试过我在下面发布的答案吗?是的,这很有效:)但是,当我访问一个存在的页面时,例如index.php
,它会加载index.php
,而不是404.php
。知道怎么做吗?如果一个页面存在,那么该页面的.php将被加载,而不是404.php。404.php将仅在page.php不存在时显示。噢。基本上,我的意图是删除并阻止在URL中使用.php
(如果用户尝试在URL中使用/add.php
,将导致404错误)。你能建议一种通过htaccess来实现这一点的方法吗?你的规则不是已经做到了吗?但是,与显示404 for.php不同,您应该显示更常见的403(禁止)错误。是的,但是如果用户尝试访问存在的页面,例如user.php
,它将加载users.php
,而不是加载404.php
。如果请求是/users
,它应该只加载users.php
。您可以通过解释它的作用或工作原理来改进这个答案。