简体   繁体   English

Zend Framework给控制器带来404错误

[英]Zend Framework Giving 404 Error For Controllers

I am using Zend Framework on Ubuntu 11.10 (my local dev machine). 我在Ubuntu 11.10(我的本地开发机器)上使用Zend Framework。 When I navigate to my application with this URL, the front page/index controller works fine: 当我使用此URL导航到我的应用程序时,首页/索引控制器可以正常工作:

http://localhost/myapp/public

So I know that for the most part everything is working. 因此,我知道大部分情况下一切正常。 The problem comes when I try to access another controller with something like: 当我尝试访问类似以下内容的另一个控制器时,就会出现问题:

http://localhost/myapp/public/faq

This returns the 404 error "The requested URL /myapp/public/faq was not found on this server." 这将返回404错误“在此服务器上找不到请求的URL / myapp / public / faq”。

I used the Zend_Tool to create the controller like "zf create controller faq" which gave me FaqController.php with a default indexAction(). 我使用Zend_Tool创建了类似“ zf create controller faq”的控制器,该控制器为我提供了带有默认indexAction()的FaqController.php。 It also created the faq.phtml view. 它还创建了faq.phtml视图。 This all works just fine on my laptop (Windows XP) so I know it has to be something with configuration. 所有这些都可以在我的笔记本电脑(Windows XP)上正常运行,因此我知道必须进行配置。

Here is my .htaccess (it's the default one): 这是我的.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]

In an attempt to get it to work, I added this into my httpd.conf file and restarted apache: 为了使其正常工作,我将其添加到了httpd.conf文件中并重新启动了apache:

<Directory />
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

When that didn't work I tried putting that directly into my .htaccess file, but that was a no-go as well. 当那行不通时,我尝试将其直接放入我的.htaccess文件,但这也是不可行的。 What am I missing? 我想念什么? What is stopping Zend from being able to rewrite and route requests? 是什么阻止Zend重写和路由请求?

[SOLVED] [解决了]

Thanks for viewing, I ended up finding the solution. 感谢您的观看,我最终找到了解决方案。 With Ubuntu, in the /etc/apache2/sites-enabled/ directory is a file called 000-default which contains configuration options. 对于Ubuntu,在/ etc / apache2 / sites-enabled /目录中是一个名为000-default的文件,其中包含配置选项。

I was unaware it was there, it had all the AllowOverride options set to None so I changed them to All, restarted Apache, and voila! 我没有意识到它在那里,它的所有AllowOverride选项都设置为None,所以我将它们更改为All,重新启动Apache,瞧!

To ensure anybody who finds this question via search has full help, I'd like to pass on to make sure mod_rewrite is enabled (mine was) by opening a terminal and running: 为了确保通过搜索找到该问题的任何人都能获得完整的帮助,我想通过打开终端并运行以确保启用了mod_rewrite(我的是)。

sudo a2enmod rewrite

That is how you enable an Apache mod in Ubuntu. 这就是在Ubuntu中启用Apache mod的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM