Apache”;找不到对象";在URL上”/错误/*”;


Apache "Object Not Found!" on URL "/error/*"

希望有人能帮我确定问题所在。我有一个完整的PHP应用程序体系结构,它是拼凑在一起的。它一直工作得很好,直到我尝试创建一个URI映射(类似于Slim框架的工作方式)。下面是一个代码示例(尽管使用另一个类似于我在过去几年中构建的CodeIgniter的架构也有同样的问题):

class Err extends Base_Director {
    function __construct() {
        /* THIS WORKS EITHER WAY! */
        $this->get('/', function(){
            echo 'Error.';
        });
        /* THIS WORKS VIA '/err/404' BUT NOT WHEN CLASS IS 'error' ('/error/404') */
        $this->get('/404', function(){
            echo 'Numeric Error 404.';
        });
        /* THIS WORK VIA '/err/four' BUT NOT WHEN CLASS IS 'error' ('/error/four') */
        $this->get('/four', function(){
            echo 'Alphanumeric Error.';
        });
        $this->submit();
    }
}

我真的认为这是Apache的一个问题,但在谷歌上搜索StackOverflow并没有找到任何有效的东西。似乎任何使用$_GET变量(带有'/error/*')的URL都会返回Apache的"找不到对象!"页面。页面上的内容为:

在此服务器上找不到请求的URL。如果您手动输入URL,请检查拼写,然后重试。

然而,其他所有URL值都运行良好。

上次我试图解决这一不便时,我认为这可能是Apache中的一个保留关键字或其他内容,但我从未仔细查看过web服务器文件,因为我担心会把事情搞砸。如果你认为我应该包括一些代码,请告诉我。这是我正在使用的.htaccess

DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(index'.php|'.swf|forums|images|css|downloads|js|robots'.txt|favicon'.ico)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ ./index.php?url=$1 [NC,QSA,L]

更新:我更深入地研究了这个问题,以帮助缩小范围。"example.com/error/404"返回"Object Not Found!"页面,正如我上面所说的,但"example.com/error/404"仍然可以通过。

更新2:这是我的httpd配置:

    DocumentRoot "C:/xampp/htdocs"
    <Directory "C:/xampp/htdocs">
        #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.4/mod/core.html#options
        # for more information.
        #
        Options Indexes FollowSymLinks Includes ExecCGI
    
        #
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   AllowOverride FileInfo AuthConfig Limit
        #
        AllowOverride All
    	Order allow,deny
    	Allow from all
        #
        # Controls who can get stuff from this server.
        #
        Require all granted
    </Directory>

我不想淹没这篇文章,这样就可以在PasteBin 上找到我的httpd文件的其余部分

用这个替换你写的所有内容,它也会这样做,并可能解决你的问题:

DirectoryIndex index.php
RewriteEngine On
RewriteRule /error/(.*) /err/$1 [L,R=301]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule (.*) /index.php?url=$1 [L]

特雷弗编辑:在编辑了httpd-multilang-errordoc.conf并注释掉Alias /error/ "C:/xampp/apache/error/"之后,我完成了上述工作。也可以通过Alias简单地更改错误重定向。这似乎是Xampp的一个功能,我添加到解决方案中可能无法与其他服务器"捆绑包"一起使用。