Zend Framework:在此服务器上找不到请求的 URL /my/path
我对 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) 中,这些正在工作:
在我的生产服务器(linux)中,我从以下位置得到“404 文件未找到”:
http://107.22.255.126/api/catalog
但这正在工作
我将其托管在 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);
}
}
?>
我已经没有主意了。我怀疑这与引导程序中的路由器有关,但找不到任何解决方案。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最后,问题是因为 httpd.conf 在目录上禁用了 .htaccess。我在 VirtualHost 下添加了AllowOverride All,它可以工作。
像这样:
在问题的评论中归功于@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:
Credit to @Corbin in the question's comment.
我在Ubuntu上遇到过这样的问题。
我进入 apache2.conf 并设置一个目录,如下所示:
最重要的一点是: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:
The most important point is: AllowOverride All
Remember to set your apache configuration:
sudo a2enmod rewrite
Then is should work.
是的,解决方案是: http://www.phpcloud.com /help/adding-rewrite-rules-to-your-application
在步骤 3 中,我没有提及,但我们没有将默认的 Elefant .htaccess 文件复制到我们的公共文件夹中。相反,我们将使用 PHPCloud 文档中 Zend 提供的那个。创建一个包含以下内容的 public/.htaccess 文件:
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: