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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8374833/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:33:54  来源:igfitidea点击:

Zend Framework: The requested URL /my/path was not found on this server

phpzend-frameworkurl-routing

提问by VHanded

I am total new to Zend Framework.

我是 Zend Framework 的新手。

I wrote a simple web service that return mock XML data with Zend Framework, with module structure like this:

我编写了一个简单的 Web 服务,它使用 Zend 框架返回模拟 XML 数据,模块结构如下:

AppName
    application
        configs
            application.ini
        modules
            default
                .....
            api
                controller
                    CatalogController.php
                view
        library
        public
            .htaccess
            index.php
        tests

In localhost (windows 7), these are working :

在本地主机(Windows 7)中,这些正在工作:

http://localhost

http://本地主机

http://localhost/api/catalog

http://localhost/api/catalog

http://localhost/default

http://本地主机/默认

in my production server (linux), I get '404 file not found' from:

在我的生产服务器 (linux) 中,我从以下位置获得“404 文件未找到”:

http://107.22.255.126/api/catalog

http://107.22.255.126/api/catalog

http://107.22.255.126/default

http://107.22.255.126/default

but this is working

但这是有效的

http://107.22.255.126

http://107.22.255.126

I host it in Amazon Web Services.

我将它托管在 Amazon Web Services 中。

Here is my .htaccess

这是我的 .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Here is my application.ini

这是我的 application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
//resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = "default"
resources.modules[] = "api"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = master

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Here is my Bootstrap.php

这是我的 Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initRoutes()
    {
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        $restRoute = new Zend_Rest_Route($front, array(), array('api'));
        $router->addRoute('api', $restRoute);
    }

}

?>

I had run out of idea. I suspect this is something related with router in bootstraper, but can't find any solution.

我已经没有主意了。我怀疑这与引导程序中的路由器有关,但找不到任何解决方案。

回答by VHanded

Finally, the problem is because httpd.conf disable .htaccess on the directory. I added AllowOverride All to it under VirtualHost, and it works.

最后,问题是因为 httpd.conf 禁用了目录上的 .htaccess。我在 VirtualHost 下向它添加了 AllowOverride All,它可以工作。

like this:

像这样:

<VirtualHost *:80>
    DocumentRoot "var/www/html/TestMVC/public"

    <Directory "var/www/html/TestMVC/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>

</VirtualHost>

Credit to @Corbin in the question's comment.

在问题的评论中归功于@Corbin。

回答by Adam Kozlowski

I had this kind of problem on Ubuntu. I went to apache2.conf and set one directory as below:

我在 Ubuntu 上遇到了这种问题。我去 apache2.conf 并设置一个目录如下:

<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

The most important point is: AllowOverride All

最重要的一点是:AllowOverride All

Remember to set your apache configuration: sudo a2enmod rewrite

记得设置你的 apache 配置:sudo a2enmod rewrite

Then is should work.

然后是应该工作。

回答by Edy Aguirre

yeap the solutions is:: http://www.phpcloud.com/help/adding-rewrite-rules-to-your-application

是的,解决方案是:http://www.phpcloud.com/help/adding-rewrite-rules-to-your-application

In step 3, I didn't mention but we didn't copy the default Elefant .htaccess file into our public folder. Instead, we're going to use the one provided by Zend in the PHPCloud documentation. Create a public/.htaccess file with the following contents:

在第 3 步中,我没有提到但我们没有将默认的 Elefant .htaccess 文件复制到我们的公共文件夹中。相反,我们将使用 Zend 在 PHPCloud 文档中提供的那个。创建一个 public/.htaccess 文件,内容如下:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
php_flag zend_codetracing.trace_enable on
php_flag zend_codetracing.always_dump on