我是Zend Framework的新手。
我写了一个简单的web服务,用Zend框架返回模拟XML数据,模块结构如下:
AppName
application
configs
application.ini
modules
default
.....
api
controller
CatalogController.php
view
library
public
.htaccess
index.php
tests
在本地主机(windows 7),这些都是工作的:
http://localhost http://localhost/api/catalog http://localhost/default 在我的生产服务器(linux)中,我从 得到'404 file not found': 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);
}
}
?>
我已经没有主意了。我怀疑这是与引导程序中的路由器有关,但找不到任何解决方案
最后,问题是因为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。
我在Ubuntu上遇到过这种问题。我进入apache2.conf并设置一个目录如下:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
最重要的一点是:
记得设置apache的配置:Sudo a2enmod rewrite
是的,解决方案是::http://www.phpcloud.com/help/adding-rewrite-rules-to-your-application
在步骤3中,我没有提到我们没有将默认的elephant .htaccess文件复制到我们的公共文件夹中。相反,我们将使用Zend在PHPCloud文档中提供的那个。创建一个公共的/。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