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

发布于 2024-12-19 16:26:15 字数 2751 浏览 3 评论 0 原文

我对 Zend Framework 完全陌生。

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

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

在 localhost (windows 7) 中,这些正在工作:

http //localhost

http://localhost/api/catalog

http://localhost/default

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

http://107.22.255.126/api/catalog

http://107.22.255.126/default

但这正在工作

http://107.22.255.126

我将其托管在 Amazon Web Services 中。

这是我的 .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]

这是我的 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

这是我的 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 am total new to Zend Framework.

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

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 :

http://localhost

http://localhost/api/catalog

http://localhost/default

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

http://107.22.255.126/api/catalog

http://107.22.255.126/default

but this is working

http://107.22.255.126

I host it in Amazon Web Services.

Here is my .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

[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

<?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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小…楫夜泊 2024-12-26 16:26:15

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

像这样:

<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>

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

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

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.

挽手叙旧 2024-12-26 16:26:15

我在Ubuntu上遇到过这样的问题。
我进入 apache2.conf 并设置一个目录,如下所示:

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

最重要的一点是:AllowOverride All

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

那么应该可以工作。

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

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

The most important point is: AllowOverride All

Remember to set your apache configuration:
sudo a2enmod rewrite

Then is should work.

暖树树初阳… 2024-12-26 16:26:15

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

在步骤 3 中,我没有提及,但我们没有将默认的 Elefant .htaccess 文件复制到我们的公共文件夹中。相反,我们将使用 PHPCloud 文档中 Zend 提供的那个。创建一个包含以下内容的 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

yeap the solutions is:: 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:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文