Zend 框架:在此服务器上找不到请求的 URL


Zend Framework: The Requested Url was not found on this server

那里

似乎有很多类似的问题,但我没有发现可以解决我的问题版本,我通过本地 OSX Web 服务器运行 zend 骨架框架。

导致标准路由如下:http://localhost/~adam/api/public/

为了我的应用程序按预期工作的目的,已更改到默认索引的路由:

     'routes' => array(
        'home' => array(
            'type' => 'Zend'Mvc'Router'Http'Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application'Controller'Testimonial',
                    'action'     => 'create',
                ),
            ),
        ),

当我创建一个新路由时,遵循同样的想法,它看起来像这样:

       'list' => array(
            'type' => 'Zend'Mvc'Router'Http'Literal',
            'options' => array(
                'route'    => '/list',
                'defaults' => array(
                    'controller' => 'Application'Controller'Testimonial',
                    'action'     => 'list',
                ),
            ),
        ),

所以它链接到同一个控制器,理论上,我应该能够访问http://localhost/~adam/api/public/list并且它应该可以工作,但是我找不到页面。

我看到有人建议它可能与当前默认的.htaccess文件有关:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::'2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

我还看到有人建议您必须编辑/etc/apache2/httpd.conf 文件,以设置AllowOverride all而不是AllowOverride none但这不起作用或我做得不正确,我尝试了一些变体,最终得到这个:

<Directory "/~adam/api/public">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

假设这是我需要的正确解决方案,有人可以指出我哪里出了问题吗? 或建议如何解决此问题。由于 conf 中有一些目录列表,我可能会更改错误的目录列表吗?

此问题由路由匹配导致。

如果您提到像"路由"=>"/list",那么它看起来来自本地主机。但是,列表是 ~adam 项目下的一个模块。

要解决此问题,请创建一个虚拟主机。如果您使用的是虚拟主机,则"/list"将从您的(虚拟)主机名中查找。

否则,您可以像这样指定,

'route' => 'http://localhost/~adam/list'

但这是不好的方法。